ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(divmod(-9, 2), divmod(9, -2))
  1. A. (-5, 1) (-5, -1)
  2. B. (-4, -1) (-4, 1)
  3. C. (-4, 1) (-5, -1)
  4. D. (-5, 1) (-4, -1)

Correct answer: A. (-5, 1) (-5, -1)

-9 // 2 floors to -5 and the remainder is 1. 9 // -2 floors to -5 and the remainder takes the divisor's sign, giving -1.

More Python Programming questions

Exams that ask this topic