0

how to write a program in python to find e**x using while function

17th Oct 2016, 2:45 PM
Navaneetha Babu
Navaneetha Babu - avatar
2 Answers
0
Hello
17th Oct 2016, 3:13 PM
Ruben_Melkumyan
Ruben_Melkumyan - avatar
0
do you really want to use while? if not it can be calculated using-> import math x=3 print(math.e**x) using while (calculating to nearest N digits) import math x=5 N=3 c0=0.0 c1=-10.0 i=0 while round(c0,N+1)!=round(c1,N+1): c1=c0 c0+=x**i/ math.factorial (i) i+=1 print(("{:."+str(N+len(str(int(c0))))+"}").format(c0)) #you can also use print(c0) too but it will give c0 without rounding it #using print(round(c0,N)) is also OK but it will not give you the exact rounded number this is not a good solution and sorry about it this may be much slower when N and x are huge so using first method is okay I think
17th Oct 2016, 3:17 PM
Sunera
Sunera - avatar