RosettaCodeData/Task/Calculating-the-value-of-e/Python/calculating-the-value-of-e-1.py
2023-07-01 13:44:08 -04:00

16 lines
285 B
Python

import math
#Implementation of Brother's formula
e0 = 0
e = 2
n = 0
fact = 1
while(e-e0 > 1e-15):
e0 = e
n += 1
fact *= 2*n*(2*n+1)
e += (2.*n+2)/fact
print "Computed e = "+str(e)
print "Real e = "+str(math.e)
print "Error = "+str(math.e-e)
print "Number of iterations = "+str(n)