ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(divmod(7, -3), 7 % -3, -7 % 3, -7 // 3)
  1. A. (-2, 1) 1 -1 -2
  2. B. (-3, 2) -2 2 -2
  3. C. (-2, -2) -2 2 -3
  4. D. (-3, -2) -2 2 -3

Correct answer: D. (-3, -2) -2 2 -3

Python's floor division and modulo pair up: 7 = -3 * (-3) + (-2), and -7 = 3 * (-3) + 2, so the second remainder is 2. -7 // 3 is -3.

More Python Programming questions

Exams that ask this topic