It has to do with how floats are stored/interpreted in python.
Look at this article for some ideas to work around this How To Stop Floating Point Arithmetic Errors in Python | by Jonathan Hsu | Code 85 | Medium
And if you want a beefier answer documentation is a great place to go: 15. Floating Point Arithmetic: Issues and Limitations — Python 3.9.1 documentation
Just a little snippet of the docs:
Many users are not aware of the approximation because of the way values are displayed. Python only prints a decimal approximation to the true decimal value of the binary approximation stored by the machine. On most machines, if Python were to print the true decimal value of the binary approximation stored for 0.1, it would have to display
That is more digits than most people find useful, so Python keeps the number of digits manageable by displaying a rounded value instead
>>> 1 / 10
And for fun here’s a tangentially related scene from Superman 3 (referenced in Office Space): Superman III â Richard Pryor â half cents and Ferrari scenes - YouTube