ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(round(2.5), round(3.5), round(-0.5), int(-2.7), -7 // 2, -7 % 2)
  1. A. 3 4 -1 -3 -3 -1
  2. B. 2 4 0 -2 -4 1
  3. C. 3 4 0 -2 -4 1
  4. D. 2 4 0 -3 -4 1

Correct answer: B. 2 4 0 -2 -4 1

Python rounds halves to the nearest even number (banker's rounding): 2, 4 and 0 (shown as 0, not -0). int() truncates toward zero (−2). // floors (−4) and % takes the divisor's sign (1), so (−7 // 2)·2 + (−7 % 2) = −7.

More Python Programming questions

Exams that ask this topic