Nth number sum in Python | Assignment Expert

Problem Statement:

In the nth number sum in python, we are given a number, we need to find the sum of the series up to that number and also need to find the sum of that series. Series is given as follows-> 1 + 1/2 + 1/3 + … + 1/n.

Code for nth number sum in python:

j = 0
series = [1]
for i in range(2, int(input('Enter nth term: '))+1):
    j = j+1/i
    series.append('1/{i}'.format(i=i))
for i in range(len(series)):
    print(series[i], end = ' ')
    if i != len(series)-1:
        print(' + ', end=' ')
print()
print('%.2f' % j)

Output:

Nth number sum in Python

Also Read:

Share:

Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at admin@copyassignment.com Thank you