ProgrammingVery hardTCS NQT · Accenture

What is printed?

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

Correct answer: C. (-3, 3) (-3, -3) 3 -3

Floor division of -9 by 4 gives -3 with remainder 3, and 9 divided by -4 gives -3 with remainder -3. The % operator follows the same sign rules as divmod.

More Python Programming questions

Exams that ask this topic