ProgrammingVery hardProduct-company MCQ pattern

What is printed?

What is printed?
total = 0.0
for _ in range(10):
    total += 0.1
print(total, total == 1.0, sum([0.1] * 10) == 1.0)
  1. A. 1.0 True True
  2. B. 0.9999999999999999 False False
  3. C. 0.9999999999999999 False True
  4. D. 1.0 True False

Correct answer: C. 0.9999999999999999 False True

A plain loop accumulates rounding error, leaving 0.9999999999999999. The built-in sum() uses compensated summation since Python 3.12 and returns exactly 1.0 here.

More Python Programming questions

Exams that ask this topic