ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(sum([1] * 10**5) == 10**5, sum([0.5] * 10**5) == 5e4, 1/3 + 1/3 + 1/3 == 1.0, 0.7 + 0.2 + 0.1 == 1.0)
  1. A. True True False True
  2. B. True False True False
  3. C. False True True False
  4. D. True True True False

Correct answer: D. True True True False

Exact fractions like 1/3 added three times give exactly 1.0, and integers add without error. But 0.1 + 0.2 is already 0.30000000000000004, and adding 0.7 leaves the sum just above 1.

More Python Programming questions

Exams that ask this topic