Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
silversteed
Group Title
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
 one year ago
 one year ago
silversteed Group Title
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
 one year ago
 one year ago

This Question is Open

rsmith6559 Group TitleBest ResponseYou've already chosen the best response.1
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.
 one year ago

hootenanny Group TitleBest ResponseYou've already chosen the best response.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.
 one year ago

hootenanny Group TitleBest ResponseYou've already chosen the best response.0
I found this technical explanation http://docs.python.org/2/tutorial/floatingpoint.html#tutfpissues
 one year ago

silversteed Group TitleBest ResponseYou've already chosen the best response.0
Thank you for the answer. I thought that was the reason for this output. Didn't expect it on a practice quiz.
 one year ago
See more questions >>>
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.