ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: C. (-4, -1) -1

Floor division gives -4 for 7 / -2 rounded toward minus infinity, and the remainder takes the sign of the divisor, so 7 - (-4)(-2) = -1.

More Python Programming questions

Exams that ask this topic