ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(0.5 == 1/2, 0.1 + 0.4 == 0.5, 0.25 + 0.25 == 0.5, 0.7 + 0.1 == 0.8)
  1. A. True True True True
  2. B. True True True False
  3. C. True False True False
  4. D. False True True False

Correct answer: B. True True True False

0.5 and 0.25 are exact in binary, and 0.1 + 0.4 rounds to exactly 0.5. 0.7 + 0.1 is 0.7999999999999999, which is not the double for 0.8.

More Python Programming questions

Exams that ask this topic