Problem: Write a Python program to find the sum of the series [1/1! + 1/2! + 1/3! +-+ 1/n!].
Using the for loop and list comprehension, we store the value of each term (i.e. 1/i!) into a list and add them all using the inbuilt
sum() method in Python.
#function to find the factorial of a number
for x in range(2, n+1):
f = f*x
#input the value of n
n = int(input("Enter value of n: "))
#find the sum of the series
sum = sum([i/factorial(i) for i in range(1, n+1)])
#output the sum
Output:Enter value of n: 50
To find the factorial of every denominator of the series, we use the
factorial() method which we have defined at the starting of the program.
We can significantly improve the efficiency of the program by running loops in the reverse direction and using dynamic programming to find the factorial of the number.