Hello!
I was writing a code and got an unexpected result, I broke it down in order to analyse it and in the end I have 8 rows of code. The problem I have is that I print x and it gives me the value 0.9 then if I say: If x < 0.9: print "Yes" it will do.
But since 0.9 isn’t < then 0.9 my program fails.
The code:
x= 0
for i in range(9):
x += 0.1
if x < 0.9:
print 'Yes'
else:
print "No"
This will print 'yes' nine times instead of yes eight times and 'No' one time.
i have phyton 2.6.5.
edit*
Worth noticing is that this code just going 99 steps work properly and write 98 'Yes' and 1 'No':
x= 0
for i in range(99):
x += 0.01
if x < 0.99:
print 'Yes'
else:
print "No"