How do you find the amount 1 + 1/2 + 1/3 + ... + 1/N?
-
A whole number of N (state 0). Figure 1 + 1/2 + 1/3 + ... + 1/N
n = input()
s = float(0)
a = floatfor i in range(1, n + 1):
a = 1 / i
s = s + a
i = i + 1print s
What's wrong?
-
Three things are wrong:
(1)
a = float
- Why is that even?(2)
a = 1 / i
- in Pitton 2 is a full division.a = 1.0 / i
(3)
i = i + 1
in cycle You can just...s = 0.0 for i in range(1, n + 1): s += 1.0 / i
print s