ProgrammingVery hardJEE Advanced · CAT placement

What is printed?

What is printed?
print(0.1 + 0.2 == 0.30000000000000004, 0.1 + 0.2 - 0.30000000000000004 == 0, '%.20f' % (0.1 + 0.2))
  1. A. False True 0.30000000000000004441
  2. B. True True 0.30000000000000004441
  3. C. True False 0.30000000000000004441
  4. D. True True 0.30000000000000004

Correct answer: B. True True 0.30000000000000004441

The literal 0.30000000000000004 is the same double as 0.1 + 0.2, so the first two comparisons are True. Printing with 20 decimals shows the exact stored value, which has more digits than the shortest repr.

More Python Programming questions

Exams that ask this topic