A community for students.
Here's the question you clicked on:
 0 viewing
seannn11
 3 years ago
>>> print(0.6//0.2)
2.0
WHY?!?
seannn11
 3 years ago
>>> print(0.6//0.2) 2.0 WHY?!?

This Question is Closed

carlsmith
 3 years ago
Best ResponseYou've already chosen the best response.0It'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.

seannn11
 3 years ago
Best ResponseYou've already chosen the best response.0how did u know it evaluated to 2.99999999999996

JulieNewbie
 3 years ago
Best ResponseYou've already chosen the best response.0It is explained here http://docs.python.org/tutorial/floatingpoint.html

carlsmith
 3 years ago
Best ResponseYou've already chosen the best response.0@seannn11 I just evaluated it interactively.
Ask your own question
Sign UpFind more explanations on OpenStudy
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.