ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
x = 0.1 * 3
y = 0.3
print(x == y, abs(x - y) < 1e-15, round(x, 15) == round(y, 15), x - y)
  1. A. False True True 5.551115123125783e-17
  2. B. True True True 0.0
  3. C. False False True 5.55e-17
  4. D. False True False 0.0

Correct answer: A. False True True 5.551115123125783e-17

0.1 * 3 is one unit in the last place above 0.3, so the direct comparison fails. The difference is about 5.55e-17, which is within 1e-15 and disappears when both are rounded to 15 places.

More Python Programming questions

Exams that ask this topic