ProgrammingVery hardTCS NQT · Accenture

What is printed?

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

Correct answer: A. True True True

0.1 * 3 is the double 0.30000000000000004, and its difference from 0.3 is 5.551115123125783e-17 with that sign. Each check compares exact binary values, so all three are True.

More Python Programming questions

Exams that ask this topic