ProgrammingHardProduct-company MCQ pattern

What is printed on the first line?

What is printed on the first line?
print(0.1 + 0.2 - 0.3 == 0, 0.1 + 0.2 - 0.3)
print(1 - 0.9 == 0.1, 1 - 0.9)
  1. A. True 5.551115123125783e-17
  2. B. False 5.551115123125783e-17
  3. C. False 0.0
  4. D. False 0.09999999999999998

Correct answer: B. False 5.551115123125783e-17

The rounding errors of 0.1, 0.2 and 0.3 do not cancel, so the result is one unit of the last place away from zero. The printed value is the exact float difference.

More Python Programming questions

Exams that ask this topic