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

>>> print(0.6//0.2) 2.0 WHY?!?

OpenStudy (carlsmith):

It's because of the way floats are stored internally. Because a mathematical float can have infinite precision, but, in real life, there's only so much memory to store one in, you get rounding errors. The expression (0.6/0.2), single slash, actually evaluates to 2.9999999999999996, not 3.0 as you'd expect. You are also using the floor division operator I think so that's where it'll be going wrong. The swapped the operators round between Python2 and Python3, so what / or // do are the opposite in each series.

OpenStudy (anonymous):

how did u know it evaluated to 2.99999999999996

OpenStudy (anonymous):

It is explained here http://docs.python.org/tutorial/floatingpoint.html

OpenStudy (anonymous):

http://pastebin.com/vhM7Pcem

OpenStudy (carlsmith):

@seannn11 I just evaluated it interactively.

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!