ProgrammingVery hardCAT · MBA placement

What is printed?

What is printed?
print(sum([0.1] * 10) == 1.0, sum([0.1] * 10), round(sum([0.1] * 10), 2))
  1. A. True 1.0 1.0
  2. B. False 0.9999999999999999 1.0
  3. C. False 1.0 1.0
  4. D. False 0.9999999999999999 0.99

Correct answer: A. True 1.0 1.0

Since Python 3.12, sum() of floats uses compensated (Neumaier) summation, so ten copies of 0.1 add to exactly 1.0. Plain left-to-right addition would give 0.9999999999999999.

More Python Programming questions

Exams that ask this topic