User-defined input-output and logical statements. Consider the following functio
ID: 3404107 • Letter: U
Question
User-defined input-output and logical statements. Consider the following function: y = e^3x^2+ 4/5x + 36 x + 1 It is desired that this function be evaluated for a variety of user-defined values of x. Create a script file/segment of code that will allow the user to neatly and professionally input a scalar OR vector value of x. Evaluate the function at 3 user-selected points as well as a single user-defined vector input. Display the result using dispO- Be sure to include some output text in addition to displaying the function evaluation result.Explanation / Answer
# python
import math
x = input("Enter a scalar or vector(space separated values): ")
def display(res):
print res
if(isinstance(x,(int,long,float))):
display(math.exp(x**2 + (4/5)*x) + 36*x + 1)
else:
vector = [float(y) for y in x.split()]
result = []
for y in vector:
result.append(math.exp(y**2 + (4/5)*y) + 36*y + 1)
display(result)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.