0

k=int(raw_input("enter a limit")) f=1 i=1 n=0 while(i<=k): f=f*i i=i+1 import math x=int(raw_input ("enter the value of x")) while(n<=k): math.exp(x)=(x**n)/f n=n+1 print"e**x=",math.exp(x) wht is wrong with this program???

18th Oct 2016, 12:13 AM
Navaneetha Babu
Navaneetha Babu - avatar
3 odpowiedzi
+ 1
line 11: math.exp(x)=(x**n)/f ^ SyntaxError: can't assign to function call line 13: print"e**x=",math.exp(x) ^ SyntaxError: invalid syntax Functions don't take values like this. Use a variable. In Python 3 at least, use parentheses for print().
18th Oct 2016, 1:30 AM
Kirk Schafer
Kirk Schafer - avatar
+ 1
Maybe you meant equivalency (==) test. This may help you debug; it runs [under python 3] and outputs tests; note I changed the test to <=. k=int(input("enter a limit")) f=1 i=1 n=0 while(i<=k): f=f*i ## k factorial : f=k! i=i+1 import math x=int(input ("enter the value of x")) while(n<=k): print(n, ":", x**n/f, ":", math.exp(x)<=(x**n/f)) n=n+1 print("e**x=", math.exp(x))
18th Oct 2016, 2:04 AM
Kirk Schafer
Kirk Schafer - avatar
0
First off, I am just trying to state an answer, not to criticize your programming skills. Ok so what I understand from you program is that you are trying to take a user input and raise it to the power of n. One of problems involves many useless variables which have no use in the program whatsoever. For example a number divided by 1 or in this case 'f' does not change the value of the number. Also there is a simpler way to exponentiate a number. You do not have to import math to do this, just write ** which means to the power of. So basically to simplify your program: you take a number input from a user and raise it to the n'th power which is zero, and so prints 1. An extra note n = n+1 is also: n+=1. By simplifying and removing unnecessary code it make it faster, easier to read, and easier to debug. Hopefully these suggestions helped you realize your mistakes.
18th Oct 2016, 1:40 AM
Nico R.W