ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: B. True False

Since Python 3.12, sum() uses compensated summation for floats, so ten 0.1 values add up to exactly 1.0 in Python 3.13. Plain repeated multiplication does not get that help: 0.1 * 3 is 0.30000000000000004, so the second check is False.

More Python Programming questions

Exams that ask this topic