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

I ran into some contradictions in the introduction to the introduction! The reading tells me that typing this Python code - >>> round (2.675,2) - into IDLE should render 2.67 but I'm getting 2.6800000000000002 instead. Could anyone explain why, please? I'm worried I'm using the wrong version of something and concerned how that will play out later in the course. Thank you!

OpenStudy (anonymous):

interesting. I am running version 2.5.4, 64bit version, in windows 8.1, and I get the same result. I do believe that the purpose of the exercise is simply to familiarize yourself with the syntax of the function "round." though that could be one of the bugs that are fixed in versions later. Testing it on 32bit 3.4.0 on winxp...Ok, in version 3.4.0 the return IS 2.67. So it appears to be a bug for that version.

OpenStudy (anonymous):

Great! Thanks for your help!

OpenStudy (anonymous):

seems to me that each build makes slightly different caliculations. maybe the devs were trying to change the accuracy.... who needs 16 decimal places?? (rhetorical question)

OpenStudy (lyrae):

Floting point numbers aren't "exact" values like integers. A float is an approximation of the actual number you want it to represent and will in most cases therefore have a slightly different value than intended. You can read more about this in the python reference docs in the "Representation Error" section: https://docs.python.org/2/tutorial/floatingpoint.html The precision of a 32/64 bit float is sufficient in most cases, but when very high precision is required (certain financial and scientific situations) you instead use special libraries like https://code.google.com/p/mpmath/ and https://docs.python.org/2/library/decimal.html to reduce or almost eliminate this problem. The reason the result differs between versions is probably not because of differences in the algoritms preforming the calucualtions, but rather changes in the function printing the value in the console. Although I'm not sure about this, it seems more likely.

OpenStudy (microbot):

I believe though you are supposed to use the 2.x one not the 3.x for the course. it should advise so in the beginning of the course.

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!