I am new to this course. In lecture 4 at 6:28, I am using Python 2.7.3, when I enter x = 0.1, when I enter x, my answer is what I expect, 0.1, not the .100000000000000001 answer on the video. Is it simply because I am using this version?: Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32 I ask because I worry when I get something different and don't know why.
I found the answer myself from looking at the link http://docs.python.org/2/tutorial/floatingpoint.html#tut-fp-issues clipped from the bottom, which precisely answers my question: meaning that the exact number stored in the computer is approximately equal to the decimal value 0.100000000000000005551115123125. In versions prior to Python 2.7 and Python 3.1, Python rounded this value to 17 significant digits, giving ‘0.10000000000000001’. In current versions, Python displays a value based on the shortest decimal fraction that rounds correctly back to the true binary value, resulting simply in ‘0.1’.
Join our real-time social learning platform and learn together with your friends!