Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 13 Online
OpenStudy (anonymous):

x = 10.0 for i in range(10): x +=0.1 print x == 11.0 Why is this false? I print x and it equals 11.0

OpenStudy (rsmith6559):

Floating point is basically a binary scientific notation. It's accuracy is greatest when dealing with numbers that are close to a power of 2. A number like 11.0, although it prints as 11.0, is probably several ten thousandths off. That's enough so that it doesn't compare equal to your literal 11.0.

OpenStudy (anonymous):

At the point in the lecture series where I'm at, the prof alludes to a future lecture that discusses the internal representation of reals ie floating point. I'm guessing that if there's a function that can specify that the real number be accurate to the nearest tenth then I imagine this code snippet could work.

OpenStudy (anonymous):

I found this technical explanation http://docs.python.org/2/tutorial/floatingpoint.html#tut-fp-issues

OpenStudy (anonymous):

Thank you for the answer. I thought that was the reason for this output. Didn't expect it on a practice quiz.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!