ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(float('0.1') + float('0.2') == float('0.30000000000000004'), 0.1 + 0.2 == 0.30000000000000004)
  1. A. True True
  2. B. True False
  3. C. False True
  4. D. False False

Correct answer: A. True True

float() and the literal both parse the decimal text to the nearest double, and 0.30000000000000004 is that same double as 0.1 + 0.2. The equality holds because the shortest repr of the sum is that string.

More Python Programming questions

Exams that ask this topic