ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
print(pow(-7, 3, 5), (-7) ** 2 % 5, -7 ** 2 % 5)
  1. A. -3 4 -4
  2. B. 2 4 1
  3. C. 2 9 4
  4. D. -2 9 1

Correct answer: B. 2 4 1

pow with a modulus takes the sign of the modulus, so -343 mod 5 = 2. (-7) ** 2 is 49, giving 4, but -7 ** 2 parses as -(7 ** 2) = -49, and -49 % 5 = 1.

More Python Programming questions

Exams that ask this topic