ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(1 - 0.9 == 0.1, round(1 - 0.9, 1) == 0.1, 1 - 0.9 > 0.09, 1 - 0.9)
  1. A. True True True 0.1
  2. B. False False True 0.1
  3. C. False True False 0.09999999999999998
  4. D. False True True 0.09999999999999998

Correct answer: D. False True True 0.09999999999999998

1 - 0.9 is a little below 0.1 in binary, so the direct equality fails. Rounding to one decimal recovers 0.1, and the difference is still greater than 0.09.

More Python Programming questions

Exams that ask this topic