ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(divmod(-7, 2), divmod(7, -2.0), 7 // -2.0, -7 % 2.5)
  1. A. (-4, 1) (-3.0, -1.0) -4.0 0.5
  2. B. (-4, 1) (-4.0, -1.0) -4.0 0.5
  3. C. (-4, -1) (-4.0, -1.0) -3.0 0.5
  4. D. (-3, 1) (-4.0, -1.0) -4.0 0.5

Correct answer: B. (-4, 1) (-4.0, -1.0) -4.0 0.5

divmod(-7, 2) floors -3.5 to -4, leaving a remainder of 1. The float version divides 7 by -2.0 to give quotient -4.0 and remainder -1.0, and -7 % 2.5 is 0.5 with the sign of the divisor.

More Python Programming questions

Exams that ask this topic