- 1
Write a python program which will ask user to enter an integer to compute the harmonic number.
If n is positive, your function will return to the sum of first n terms in harmonic series:1/1+1/2+1/3...+1/n. If n is non postive your program will output 0. For example if user entered 4 your program will output something like 2.083333333333 if user entered 7 program will output 2.5928714285
5 odpowiedzi
+ 1
the harmonic series is the infinite sum over i of 1/i
0
You have to be careful with this one. Do you want maximum precision?
0
what is harmonic series?
0
No
0
Sorry for coming back this late.
There is actually a 1e-12 difference between the two ways at n = 10**6
both ways:
sum(1/i for i in range(1, n+1)) for MINIMUM precision
sum(1/i for i in range(n, 0, -1)) for MAXIMUM precision