Answer to Question #223963 in Python for anand

Question #223963
Sum of N terms in Harmonic series

Given integer 

N as input, write a program to display the sum of the first N terms in harmonic series.

The series is: 1 + 1/2 + 1/3 + 1/4 + 1/5 ... + 1/N (N terms).

Input

The first line of input is an integer 

N.

Output

Print the sum rounded upto 2 decimal places.

Explanation

For 

N = 5

The sum of first 5 terms in harmonic series is 1 + 1/2 + 1/3 + 1/4 + 1/5

So, the output should be 

2.28.

Sample Input 1
5
Sample Output 1
2.28
Sample Input 2
3
Sample Output 2
1.83

1
Expert's answer
2021-08-09T02:30:14-0400
N = int(input('Enter integer here: '))
j = 0
for i in range(1,N+1):
  j = j + 1/i
print(round(j,2))

Enter integer here: 5
2.28

Enter integer here: 3
1.83

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS