ProgrammingHardProduct-company MCQ pattern

What is printed on the first line?

What is printed on the first line?
print(7 % -3, -7 % 3, 7 % 3, -7 % -3)
print(-7 // -3, 7 // -3, -7 // 3)
  1. A. -2 2 1 -1
  2. B. -1 2 1 -2
  3. C. -2 2 1 -3
  4. D. -2 3 1 -1

Correct answer: A. -2 2 1 -1

The remainder takes the sign of the divisor, so 7 % -3 is -2 and -7 % -3 is -1. Floor division of negative values rounds down, not toward zero.

More Python Programming questions

Exams that ask this topic