ProgrammingHardProduct-company MCQ pattern

What is printed?

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

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

divmod(7.5, 2) gives quotient 3.0 and remainder 1.5. For a negative divisor the remainder takes the divisor's sign, so 7.5 % -2 is -0.5. Floor division of -7.5 by 2 is -4.0.

More Python Programming questions

Exams that ask this topic