ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
x = 0.1 + 0.2
print(x > 0.3, round(x, 15) == 0.3, x - 0.3 < 1e-9, '%.17g' % x)
  1. A. True True False 0.3
  2. B. True True True 0.30000000000000004
  3. C. False True True 0.3
  4. D. True False True 0.30000000000000004

Correct answer: B. True True True 0.30000000000000004

0.1 + 0.2 is slightly above 0.3, and rounding to 15 digits hides that gap. The %.17g format shows the full stored value, which is 0.30000000000000004.

More Python Programming questions

Exams that ask this topic