ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(pow(-2, 3, 5), pow(3, -1, 7), pow(2, 10, -7), (-2) ** 3 % 5)
- A. 2 5 2 2
- B. 2 5 -5 2
- C. 3 5 -5 2
- D. 2 4 -5 2
Correct answer: B. 2 5 -5 2
Three-argument pow with a negative modulus returns a result with the modulus's sign, and 1024 is 2 mod 7, so the result is 2 - 7 = -5. pow(3, -1, 7) is the inverse 5 because 3 * 5 = 15 is 1 mod 7, and (-8) % 5 is 2.
More Python Programming questions
- What is printed? python try: s = str(10 4301) print(len(s)) except ValueError: print('too many digits')
- What is printed? python print(' xt'.strip() == 'x', 'atb'.expandtabs(4), len('atb'.expandtabs(4)), 'abrncd'.splitlines())
- What is printed? python print('²'.isdigit(), '²'.isdecimal(), '²'.isnumeric(), '٥'.isdecimal())
- What is printed? python print(len('é'.encode('utf-8')), len('é'.encode('utf-16-le')), len('a€'.encode()), b'xc3xa9'.decode())
- What is printed? python print(f"{12:>{5}}|{3.14159:.{2}f}|{'ab':^6}")
- What is printed? python x = 12 print(x & -x, x ^ (x - 1), (x & (x - 1)) == 0, -x & x == x & -x)