ProgrammingVery hardProduct-company MCQ pattern

What is printed?

What is printed?
print(sum([0.1] * 3) == 0.3, sum([0.1] * 3, 0.0) == 0.30000000000000004, sum([1e100, 1.0, -1e100]))
  1. A. True True 1.0
  2. B. False True 0.0
  3. C. False True 1.0
  4. D. False False 1.0

Correct answer: C. False True 1.0

Adding three 0.1 values gives 0.30000000000000004 rather than the double for 0.3. Since Python 3.12, sum() uses compensated summation, which recovers the 1.0 that a plain loop would lose.

More Python Programming questions

Exams that ask this topic