For my assignment I have to check if a calculated value is within 0.05 of 0.5. To do this i thought subtracting one from another, taking the absolute value and checking if that is smaller or equal then 0.05 should do the trick. However when i try this piece of code.
x = abs(0.5 - 0.55)
if x <= 0.05:
print 'x is', x, 'x = yes'
else:
print 'x is', x, 'x = no'
y = abs(0.4 - 0.45)
if y <= 0.05:
print 'y is', y, 'y = yes'
else:
print 'y is', y, 'y = no'
The returns a very weird output.
x is 0.05 x = no
y is 0.05 y = yes
Where y is seen as 0.05 but x is not seen as 0.05, however both values are equal to 0.05 according to python. Am I doing something wrong?