ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(-7 % 4, -7 % -4, 7 % -4, (-7) % 4 == -7 % 4)
  1. A. 1 -3 -1 True
  2. B. 1 -3 -1 False
  3. C. -3 -3 1 True
  4. D. 1 4 -1 True

Correct answer: A. 1 -3 -1 True

Modulo takes the divisor's sign, so -7 % 4 is 1 and 7 % -4 is -1. -7 % -4 is -3, and the parentheses change nothing because unary minus on a literal binds to 7 first.

More Python Programming questions

Exams that ask this topic