ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
print(repr(1e16), repr(1e15 + 0.3), 1e16 == 10**16, 1e16 + 1 == 1e16)
  1. A. 1e+16 1000000000000000.2 True True
  2. B. 1e+16 1000000000000000.3 True True
  3. C. 1e+16 1000000000000000.2 False True
  4. D. 1e+16 1000000000000000.2 True False

Correct answer: A. 1e+16 1000000000000000.2 True True

Near 1e16 the gap between adjacent doubles is 2, so adding 1 rounds back to 1e16. repr shows the shortest string that round-trips, which is why 1e15 + 0.3 prints as ...0.2 rather than the decimal value you typed.

More Python Programming questions

Exams that ask this topic