ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
print(0.1 * 3 == 0.3, abs(0.1 * 3 - 0.3) < 1e-9)
  1. A. True True
  2. B. False True
  3. C. False False
  4. D. True False

Correct answer: B. False True

0.1 * 3 is stored as 0.30000000000000004, which differs from 0.3, so the exact comparison fails. The tolerance check passes because the difference is far below 1e-9.

More Python Programming questions

Exams that ask this topic