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
Recommended Post:
Python Program to check vowel or Consonant
Program to check character is alphabet or not in Python
Python to check whether the year is leap or not
Python to check if number is Positive, Negative or 0
Python Program to solve Quadratic equation
Program to generate Random numbers in Python
Program to swap two numbers in Python
Program to Add two numbers in Python
Python to convert decimal to binary, octal and hexadecimal
Python Program to find large number among three numbers