ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
print(round(-0.5), round(0.5), round(1.5), round(-1.5), round(2.5))
  1. A. 0 1 2 -1 2
  2. B. 0 0 2 -2 3
  3. C. 0 0 3 -2 2
  4. D. 0 0 2 -2 2

Correct answer: D. 0 0 2 -2 2

round uses half-to-even for exact halves. -0.5 and 0.5 both go to 0, 1.5 goes to 2, -1.5 goes to -2, and 2.5 goes to 2.

More Python Programming questions

Exams that ask this topic