Find the Sum of the series: 1+1/2+1/3..+ 1/N in Python

Find the Sum of the series: 1+1/2+1/3..+ 1/N in Python

In this, you will learn how to write a Python program to find the Sum of the series: 1 + 1/2 + 1/3 +… .. + 1 / N.

Steps

1. Take the number of terms to find the sum of the series.

2. Sum is initialized to zero.

3. Use a for loop to find the sum of the series and increment number by one at every iteration.

4. Print the whole series after rounding it to three decimal places.

5. Exit.


Let's take a look at the code how to find the sum of series in Python Programming.

Python Code:

n = int(input("enter number of terms:"))
a = []
sum = 0
for i in range(0,n):
i = i+1
x = str(1) + '/' + str(i)
sum = sum + (1/i)
a.append(x)
print(a)
print('sum of series is:',round(sum,3))
Output:
enter number of terms:7
['1/1', '1/2', '1/3', '1/4', '1/5', '1/6', '1/7']
sum of series is: 2.593