ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(round(1e16 + 2), round(9.5), round(10.5), round(-9.5))
  1. A. 10000000000000000 10 11 -10
  2. B. 10000000000000002 10 11 -10
  3. C. 10000000000000002 9 10 -10
  4. D. 10000000000000002 10 10 -10

Correct answer: D. 10000000000000002 10 10 -10

1e16 + 2 is exactly representable, and round of a float that is already whole returns the same integer. Halves go to the even neighbour, so 9.5 and 10.5 both give 10, and -9.5 gives -10.

More Python Programming questions

Exams that ask this topic