ProgrammingModerateTCS NQT · Infosys

What is printed on the second line?

What is printed on the second line?
import math
print(math.isclose(1e9, 1e9 + 1e-3), math.isclose(1e9, 1e9 + 1, rel_tol=1e-9))
print(round(1e9 + 0.5) - 1e9, 1e9 + 0.5 == 1000000000.5)
  1. A. 0.0 True
  2. B. 0.0 False
  3. C. 1.0 True
  4. D. 0.5 True

Correct answer: A. 0.0 True

round uses half-to-even, so 1000000000.5 rounds to the even 1000000000. The literal 1e9 + 0.5 is exact at this magnitude, so the equality holds.

More Python Programming questions

Exams that ask this topic