ProgrammingHardProduct-company MCQ pattern

What is printed?

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

Correct answer: C. (-3, 2) (-3, -2) (-3.0, 3.5)

divmod floors the quotient and gives the remainder the divisor's sign: -7 = (-3)(3) + 2 and 7 = (-3)(-3) + (-2). For floats the quotient is -3.0 and the remainder is 3.5.

More Python Programming questions

Exams that ask this topic