ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(str(1.1 * 1.1), str(1.21), 1.1 * 1.1 == 1.21, abs(1.1 * 1.1 - 1.21) < 1e-12)
  1. A. 1.21 1.21 True True
  2. B. 1.2100000000000002 1.21 True True
  3. C. 1.2100000000000002 1.21 False False
  4. D. 1.2100000000000002 1.21 False True

Correct answer: D. 1.2100000000000002 1.21 False True

1.1 * 1.1 is a little above 1.21 in binary, so its shortest repr shows the extra digit. The tolerance check succeeds because the error is far below 1e-12.

More Python Programming questions

Exams that ask this topic