Sum of N terms in Harmonic series
This Program name is Sum of N terms in Harmonic series. Write a Python program to Sum of N terms in Harmonic series, it has two test cases
The below link contains Sum of N terms in Harmonic series question, explanation and test cases
https://docs.google.com/document/d/1kZEEzRlzAo_HT0I9HineNAMs_3PwlU2_/edit?usp=sharing&ouid=104486799211107564921&rtpof=true&sd=true
We need exact output when the code was run
def sum1(x):
col = 1
answer = 0.0
for col in range(1, x+1):
answer = answer + 1/col
return answer
# Testing Code
print("Sample Input 1\n 5")
n = 5
print("Sample Output 1\n", round(sum1(n), 2))
print("\nSample Input 2\n 3")
n = 3
print("Sample Output 2\n", round(sum1(n), 2))
Comments
Leave a comment