ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(0.1 + 0.2 == 0.3, round(0.1 + 0.2, 10) == 0.3, 3 * 0.1 == 0.3 - 0.2 + 0.1)
  1. A. False False True
  2. B. True True False
  3. C. False True True
  4. D. False True False

Correct answer: D. False True False

0.1 + 0.2 is 0.30000000000000004 in binary floating point, so the first check fails. Rounding to 10 decimals gives the nearest double to 0.3, so the second is True. 0.3 - 0.2 + 0.1 is 0.19999999999999998, not 0.30000000000000004, so the third is False.

More Python Programming questions

Exams that ask this topic