I am working on a project for school in python 2 and I am having a lot of trouble with one of the problems:
Write a program that computes the following sum: sum = 1.0/1 + 1.0/2 + 1.0/3 + 1.0/4 + 1.0/5 + .... + 1.0/N N is an integer limit that the user enters.
For example:
Enter N: 4
Sum is: 2.08333333333
The code I currently have written is:
NumOfN = int(input("What is N? : "))
total = 0
for i in range (NumOfN):
NextNum = 1.0/(NumOfN)
total = NextNum
NumOfN = NumOfN-1
print "the sum is", total
However whenever I run this I get an output of "1.0" any help would be greatly appreciated.
-Thank you.
sum.total = sum([1.0/x for x in range(1,NumOfN+1)])