ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
print(0.1 + 0.2 + 0.3 == 0.6, 0.3 + 0.2 + 0.1 == 0.6, 0.1 + (0.2 + 0.3) == 0.6)
  1. A. False True True
  2. B. True True True
  3. C. False False True
  4. D. False True False

Correct answer: A. False True True

Floating-point addition is not associative, so the grouping and order change the rounding error. Here (0.1 + 0.2) + 0.3 misses 0.6, while the other two groupings land exactly on it.

More Python Programming questions

Exams that ask this topic