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
This Post Has One Comment
Abdiel Patton