Calculate Euler number “e” in Python

Here’s an example of how to calculate Euler number. The higher the number of iterations the more precise Euler number will be, but the time to compute it grows exponentially :) Learn more about Euler number

>>> a = 1.0
>>> for z in range(1, 100):
...     a += (1.0 / reduce(lambda x,y:x*y, [1]+range(1,z+1)))
>>> a
2.7182818284590455

Leave a Reply

Your email address will not be published. Required fields are marked *