# Euler’s Number

The number e is a famous irrational number called Euler’s number after Leonhard Euler a Swiss Mathematician (1707 – 1783). Number e is considered to be one of the most important numbers in mathematics.

The first few digits are: 2.7182818284590452353602874713527… It has an infinite number of digits with no recurring pattern. It cannot be written as a simple fraction.

Number e is the limit of (1 + 1/n)n as n approaches infinity:

Number e is a mathematical constant that is the base of the natural logarithm: the unique number whose natural logarithm is equal to one. Find out more on https://en.wikipedia.org/wiki/E_(mathematical_constant).

In this challenge we will use a Python script to calculate an approximation of e using three different approaches. The first approach as described above as already been implemented in the above Python trinket.

#### Calculating e using an iterative approach

Euler’s number, e, can also be calculated as the sum of the infinite series:

Complete your Python script to implement this infinite series using an iterative approach. (Method 2)

#### Calculating e using a continuous fraction (iterative approach)

A less common approach to calculate number e is to use a continued fraction based on the following sequence:

Continued Fraction:

Complete your Python script to implement this continued fraction. (Method 3)
[pms-restrict display_to=”not_logged_in” message=” “]

#### Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
[/pms-restrict] [pms-restrict subscription_plans=”14217″ message=” “]

#### Solution...

You are viewing this solution as part of your full membership subscription!

Python Code

#### Python Code

#Calculating an approximation of Euler's Number

#Method 1: e = limit of (1 + 1/n)^n as n approaches infinity
print("Method 1: e = limit of (1 + 1/n)^n as n approaches infinity")
n=10000000
e = (1+1/n)**n
print(e)

#Method 2: Using an infinite series (Iterative approach)
print("\nMethod 2: Using an infinite series (Iterative approach)")
e = 1
quotient = 1
for i in range(1,100):
quotient = quotient * i
e = e + 1/quotient
print(e)

#Method 3: Using a continued fraction (Iterative approach)
print("\nMethod 3: Using a continued fraction (Iterative approach)")

n = 100 # number of iterations
e = 0
for i in range(n, 0, -1):
if i % 3 == 1:
j = 2 * int(i / 3)
else:
j = 1
e = 1.0 / (e + j)
e = e+1
print(e)
[/pms-restrict]

Did you like this challenge?

Click on a star to rate it!

Average rating 4.6 / 5. Vote count: 7

No votes so far! Be the first to rate this post.

As you found this challenge interesting...