Python program to estimate the value of mathematical constant ‘e’ according to the formula 1 + 1/1! + 1/2! +1/3! + 1/4! ….. 1/n!

Here is a code for the python program to estimate the value of the mathematical constant ‘e’ according to the formula 1 + 1/1! + 1/2! +1/3! + 1/4! ….. 1/n!

First, we will define a function for factorial.

Then there is the code to estimate the value of e.

#Python program to estimate the value of mathematical constant ‘e’ according to the formula 1 + 1/1! + 1/2! +1/3! + 1/4! .....

def factorial(factorial_user_input):
    fact = 1
    while 1 <= factorial_user_input:
        fact *= factorial_user_input
        factorial_user_input -= 1
    return fact

user_input = int(input('Enter the n term in 1/n!: '))
e = 0
f = 0
while user_input > 0:
    e = e + ( 1 / factorial(f))
    f = f + 1
    user_input = user_input - 1
print(e)

# This code is contributed by Ahmad Shafiq

callout-flag

Love this read? Subscribe to Modernage!

Do you have any queries? You can ask in the comments. We, at Modernage answer each and every question, asked in the comments, so If you have any queries, or you want to know about any specific platform you can ask in the comments below

Author

This Post Has 7 Comments

Leave a Reply

girl-carrying-document

More Articles.

SUBSCRIBE TO MODERNAGE

Top Posts

Author

SUBSCRIBE TO MODERNAGE

Technology

SUBSCRIBE TO MODERNAGE

Python

girl-carrying-document

More Articles.