ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(divmod(7.5, 2), divmod(-7.5, 2), 7.5 % -2, -7.5 // -2)
  1. A. (3.0, 1.5) (-4.0, 0.5) -0.5 3.0
  2. B. (3.0, 1.5) (-4.0, 0.5) -0.5 4.0
  3. C. (3.0, 1.5) (-3.0, 0.5) -0.5 3.0
  4. D. (3.0, 1.5) (-4.0, 0.5) 0.7 3.0

Correct answer: A. (3.0, 1.5) (-4.0, 0.5) -0.5 3.0

Float divmod uses the same floor rules as ints, so 7.5 divided by 2 is 3.0 with remainder 1.5. The remainder of 7.5 by -2 takes the divisor's sign, -0.5, and -7.5 // -2 floors 3.75 to 3.0.

More Python Programming questions

Exams that ask this topic