ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(round(-2.5), round(-3.5), round(7, -1), round(15, -1), round(25, -1))
  1. A. -3 -4 10 20 30
  2. B. -2 -4 10 10 20
  3. C. -2 -3 10 20 20
  4. D. -2 -4 10 20 20

Correct answer: D. -2 -4 10 20 20

round() with no digits uses half-to-even, so -2.5 becomes -2 and -3.5 becomes -4. For round(x, -1), 15 and 25 are exact halves and go to the even tens, 20 and 20.

More Python Programming questions

Exams that ask this topic