ProgrammingVery hardProduct-company MCQ pattern

What is printed on the first line?

What is printed on the first line?
print(pow(2, -1, 5), pow(3, -1, 7), pow(2, -3, 9))
try:
    print(pow(2, -1, 4))
except ValueError as e:
    print('ValueError')
  1. A. 3 5 5
  2. B. 3 5 8
  3. C. 3 3 8
  4. D. 5 5 8

Correct answer: B. 3 5 8

Since Python 3.8, pow with a negative exponent and a modulus returns the modular inverse: 2 * 3 = 6 is 1 mod 5, and 3 * 5 = 15 is 1 mod 7. 2 has no inverse modulo 4, which raises ValueError.

More Python Programming questions

Exams that ask this topic