ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(pow(10, 18, 7), (-3) ** 3 % 7, pow(-3, 3, -7), -3 ** 3 % 7)
  1. A. 0 1 6 1
  2. B. 1 1 -6 -27
  3. C. 1 -1 -6 2
  4. D. 1 1 -6 1

Correct answer: D. 1 1 -6 1

10 is 3 mod 7 and 3 to the 6th power is 1, so 3**18 is 1. -27 % 7 is 1, and pow(-3, 3, -7) takes the sign of the modulus, giving -6. The unary minus in -3 ** 3 applies after the power, so it is -27.

More Python Programming questions

Exams that ask this topic