ProgrammingHardProduct-company MCQ pattern

What is printed?

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

Correct answer: C. (-4, 3) (-4, -3) (-4.0, 3.0)

divmod floors the quotient and gives the remainder the sign of the divisor. -17 = (-4)(5) + 3, and 17 = (-4)(-5) + (-3). The float version returns floats, so the quotient is -4.0.

More Python Programming questions

Exams that ask this topic