ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(0.1 * 0.1 == 0.01, 0.1 * 0.1, round(0.1 * 0.1, 2) == 0.01)
  1. A. False 0.010000000000000002 True
  2. B. True 0.01 True
  3. C. False 0.01 True
  4. D. False 0.010000000000000002 False

Correct answer: A. False 0.010000000000000002 True

0.1 * 0.1 is not the double nearest 0.01, so the direct comparison is False and the repr shows the extra digits. Rounding to two decimals returns the double for 0.01, so that comparison is True.

More Python Programming questions

Exams that ask this topic