EN
Python - math.e property example
0 points
The Math.E
property returns e mathematical constant (2.718281828459045...
).
e
is called Euler's number or Napier's constant. However, it was discovered by Jacob Bernoulli. It is a mathematical constant used as the base of the natural logarithm.
xxxxxxxxxx
1
import math
2
3
print(math.e) # 2.718281828459045
4
5
print(math.exp(1)) # 2.718281828459045
6
print(math.exp(2)) # 7.38905609893065
7
print(math.exp(3)) # 20.085536923187668
Syntax |
xxxxxxxxxx 1 math.e |
Result | e number (2.718281828459045... ). |
Description |
|
To calculate e
the following function with infinity series can be used to get a better precision infinite number of iterations with big precision numbers.
xxxxxxxxxx
1
import math
2
3
4
def calculateE(iterations):
5
return sum(1 / float(math.factorial(i)) for i in range(iterations))
6
7
8
print(calculateE(1)) # 1.0
9
print(calculateE(2)) # 2.0
10
print(calculateE(5)) # 2.708333333333333
11
print(calculateE(10)) # 2.7182815255731922
12
print(calculateE(20)) # 2.7182818284590455