I'm currently trying to solve some problems in Project Euler. As part of the first question, I need to find the sum of all the multiples of 5 under 1000. Here's what I wrote:
fiveSum = 5 #the sum of the multiples
n = 1.0 #number of the multiples
i = 5 #represents the current multiple of 5
while (i + 5 < 1000):
i = i * (1 + (1 / n))
fiveSum += i
n += 1
When it's done, for some reason n=200, when it should be 199. When i=995.0, the boolean expression still equals "true". I tried adding:
print i + 5 < 1000
print i + 5
print 995.0 + 5 < 1000
to see what does the computer think when i=995.0, and it says:
True
1000.0
False
Does anyone have any idea what am I missing? When I do a similar loop for multiples of 3 it comes out fine.