ProgrammingHardProduct-company MCQ pattern

What is printed?

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

Correct answer: A. 0.5 -0.5 0.0

Float % follows floor division, so -7.5 = -4 * 2 + 0.5. A negative divisor gives a remainder with the divisor's sign, so 7.5 % -2 is -0.5.

More Python Programming questions

Exams that ask this topic