Python Program to Find the Sum of the Series: 1 + 1/2 + 1/3 + ….. + 1/N

Python program to find sum of the series 1/1! + 2/2! + 3/3! + ……1/n!; Through this tutorial, i am going to show you how to find sum of the series 1/1! + 2/2! + 3/3! + ……1/n! in python.

Python Program to Find The Sum of Series 1/1! 2/2! 3/3! …1/n!

See the following python program to find sum of the series : 1 + 1/2 + 1/3 + ….. + 1/N using for loop and function; as shown below:

  • Python Program to Find the Sum of the Series: 1 + 1/2 + 1/3 + …..+ 1/N using For Loop
  • Python Program to Find Sum of Series 1/1! 2/2! 3/3! …1/n! Using Function

Python Program to Find the Sum of the Series: 1 + 1/2 + 1/3 + …..+ 1/N using For Loop

  • Get input number of terms to find the sum of the series from user.
  • Initialize the sum variable to 0.
  • Use a for loop ranging from 1 to the number and find the sum of the series.
  • Print the sum of the series after rounding it off to two decimal places.
#Python Program to Find Sum of Series 1/1!   2/2!   3/3!   …1/n! using for loop
n=int(input("Enter the number of terms: "))
sum1=0
for i in range(1,n+1):
    sum1=sum1+(1/i)
print("The sum of series is",round(sum1,2))

Output

Enter the number of terms:  5
The sum of series is 2.28

Python Program to Find Sum of Series 1/1! 2/2! 3/3! …1/n! Using Function

  • Get the input number of the term of series from the user.
  • Next, Define a function and write logic to computes the sum of series for a given number.
  • Call function with number.
  • Print the sum of the series return by function.
#Python Program to Find Sum of Series 1/1!   2/2!   3/3!   …1/n! using function
#define a function
def sumOfSeries(num): 
      
    # Computing MAX 
    res = 0
    fact = 1
      
    for i in range(1, num+1): 
        fact *= i 
        res = res + (i/ fact) 
          
    return res 
      
  
n=int(input("Enter the number of terms: "))
print("Sum: ", sumOfSeries(n)) 
Enter the number of terms:  5
Sum:  2.708333333333333

Recommended Python Tutorials

Leave a Comment