ProgrammingHardProduct-company MCQ pattern

What is printed on the second line?

What is printed on the second line?
def mod(a, m):
    r = a % m
    return r + m if r < 0 else r
print(mod(-1, 5), mod(-5, 5), mod(-6, 5))
print(-1 % 5, (-1) % 5 == 4, -1 % -5)
  1. A. 4 False -1
  2. B. 4 True -1
  3. C. 1 True -1
  4. D. 4 True 4

Correct answer: B. 4 True -1

Python's % already returns a result with the sign of the divisor, so the helper's correction never runs. -1 % 5 is 4 and -1 % -5 is -1, since the result takes the divisor's sign.

More Python Programming questions

Exams that ask this topic