ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
print(0.1 * 3 == 0.3, 0.1 * 3, 0.3 * 3 == 0.9)
  1. A. False 0.30000000000000004 False
  2. B. True 0.3 True
  3. C. False 0.3 False
  4. D. False 0.30000000000000004 True

Correct answer: A. False 0.30000000000000004 False

0.1 * 3 and 0.3 * 3 both carry binary rounding error, so the equality tests with the decimal literals fail even though the maths says they hold.

More Python Programming questions

Exams that ask this topic