Question

Use Python Write a program that asks the user to enter the expression of a function...

Use Python
Write a program that asks the user to enter the expression of a function to a single variable x. From this expression, using the sympy library, do the following:

Calculate the images for x ranging from 0 to 19
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The python code is below


from sympy import *

x=symbols('x') # As there is only one symbol so we define x as our symbol

# taking expression input from the user
exp=sympify(input("enter the expression in form of x as variable:"))

# iterating from 0 to 20 and printing the value of expression.
for i in range(20):
   result=exp.evalf(subs={x:i})
   print('result of expression with x={} is: {:.2f}'.format(i,result))

CODESCREEN SHOT- Maintain the indentation i.e spaces of the above by checking the screen shot.

Make sure you have sympy package installed. If not go to command prompt and type pip install sympy

OUTPUT SCREEN- In the input of expression I have given x+1 . you can also give x*2+4

Add a comment
Know the answer?
Add Answer to:
Use Python Write a program that asks the user to enter the expression of a function...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT