Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

seannn11 Group Title

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

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. carlsmith Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • 2 years ago
  2. seannn11 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    how did u know it evaluated to 2.99999999999996

    • 2 years ago
  3. JulieNewbie Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

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

    • 2 years ago
  4. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    http://pastebin.com/vhM7Pcem

    • 2 years ago
  5. carlsmith Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @seannn11 I just evaluated it interactively.

    • 2 years ago
    • Attachments:

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.