ProgrammingHardTCS NQT · Infosys

What is printed?

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

Correct answer: B. True False False

1/3 times 3 rounds to exactly 1.0. 2/3 is stored with rounding, so 1 - 2/3 is a different double from 1/3, and 0.1 + 0.2 - 0.3 is about 5.6e-17, not zero.

More Python Programming questions

Exams that ask this topic