Answer to Question #225600 in Python for kaavya

Question #225600

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 up to 2 decimal places.

Explanation

For

N = 5The 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-15T01:16:32-0400
n = int(input())
sum = 0
for i in range(1, n + 1):
    sum += 1 / i
print("%.2f" % sum)

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

ganesh
14.08.21, 10:42

please slove above question

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS