Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

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

MIT 6.00 Intro Computer Science (OCW)
See more answers at
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly


Get your free account and access expert answers to this and thousands of other questions

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.
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.
I found this technical explanation

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

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

Not the answer you are looking for?

Search for more explanations.

Ask your own question