Languages
[Edit]
EN

Python - math.e property example

0 points
Created by:
Teilsa
345

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.

import math

print(math.e)  # 2.718281828459045

print(math.exp(1))  # 2.718281828459045
print(math.exp(2))  # 7.38905609893065
print(math.exp(3))  # 20.085536923187668

1. Documentation

Syntax
math.e
Resulte number (2.718281828459045...).
Description

math.e constant returns the Euler's number.

2. e number approximation example

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.

import math


def calculateE(iterations):
    return sum(1 / float(math.factorial(i)) for i in range(iterations))


print(calculateE(1))    # 1.0
print(calculateE(2))    # 2.0
print(calculateE(5))    # 2.708333333333333
print(calculateE(10))   # 2.7182815255731922
print(calculateE(20))   # 2.7182818284590455

References

  1. e (mathematical constant) - Wikipedia

Python - math module

Native Advertising
šŸš€
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ā¤ļøšŸ’» šŸ™‚

Join