ProgrammingHardTCS NQT · Infosys

What is printed?

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

Correct answer: A. True True False True

0.1 + 0.2 is slightly above 0.3, and rounding to two places gives exactly 0.3. 3 * 0.1 is not the double for 0.3, but 1 / 3 * 3 rounds back to 1.0.

More Python Programming questions

Exams that ask this topic