Copyright (C) 2010-2020 Luke Olson
Copyright (C) 2020 Andreas Kloeckner
What will the following code snippet do?
from time import sleep
x = 0.0
while x != 1.0:
x += 0.1
print(repr(x))
sleep(0.1)
0.1 0.2 0.30000000000000004 0.4 0.5 0.6 0.7 0.7999999999999999 0.8999999999999999 0.9999999999999999
--------------------------------------------------------------------------- KeyboardInterrupt Traceback (most recent call last) <ipython-input-1-92a2572106f3> in <module>() 7 print(repr(x)) 8 ----> 9 sleep(0.1) KeyboardInterrupt:
How do you prevent that from happening?