I am trying to make a python script but cant get it to work right. I am dealing with very small numbers and python doesn't seem to like it. Here is my script:
x = 0
while x < 3:
x += .0001
if x == 2.5:
print "X is now: ", x
break
else:
print x
When I run it in PyCharm I get this output (I've shortened it so you don't have to scroll through a bunch of numbers.)
2.4988
2.4989
2.499
2.4991
2.4992
2.4993
2.4994
2.4995
2.4996
2.4997
2.4998
2.4999
2.5
2.5001
2.5002
2.5003
2.5004
2.5005
2.5006
2.5007
2.5008
2.5009
2.501
Pycharm is acting as if my "if" statement doesn't exist. It skips right over the number 2.5 without running
if x == 2.5:
print "X is now: ", x
break
I figured it's something to do with the way my computer is running those numbers and the 2.5 i'm seeing is really 2.5000001 or something but I don't know. I've tried putting the numbers into scientific notation hoping it would help but instead I get the error "Too much output to process"
I'm fairly new to python and am starting to get annoyed by this. Any and all help it appreciated. Thanks.