ProgrammingVery hardTCS NQT · Accenture

What is printed?

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

Correct answer: A. True False True True

0.1 + 0.2 is slightly above 0.3. 0.3 - 0.1 is 0.19999999999999998, while doubling 0.2 and subtracting 0.2 from 0.4 both land exactly on the nearest doubles.

More Python Programming questions

Exams that ask this topic