ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(str(round(2.5)), str(round(3.5)), round(2.5 + 0.0001), round(-2.5 - 0.0001))
  1. A. 2 4 3 -3
  2. B. 2 4 2 -2
  3. C. 2 3 3 -3
  4. D. 3 4 3 -3

Correct answer: A. 2 4 3 -3

round uses half-to-even for exact halves, so 2.5 becomes 2 and 3.5 becomes 4. Adding or subtracting a tiny amount moves the value past the midpoint, so it rounds away from zero.

More Python Programming questions

Exams that ask this topic