ProgrammingVery hardTCS NQT · Accenture

What is printed?

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

Correct answer: B. False False False

0.2 + 0.4 is 0.6000000000000001, and adding 0.1 pushes the total past 0.7, so each grouping misses the target. The printed values are all False, even though the mathematical sum is exactly 0.7.

More Python Programming questions

Exams that ask this topic