Competitive Programming Questions in Python |
In the article, we are going to write a python code to compute the value of e^x
If you are looking for a Python Tutorial then it's here
def expo(x):
epsilon = 0.00001
multiBy = x
term = 1
total = 1
nxtInSeq = 1.0
while abs(term) > epsilon:
divBy = nxtInSeq
term = term*multiBy/divBy
total += term
nxtInSeq += 1
print(total)
expo(1)
The output of the above code is:
2.7182815255731922
Comments
Post a Comment