ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
print(pow(-7, 3, 5), (-7) ** 2 % 5, -7 ** 2 % 5)
- A. -3 4 -4
- B. 2 4 1
- C. 2 9 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
- What is printed? python print(2100 % 7, pow(2, 100, 7), pow(2, 100, 1))
- What is printed? python x = 1020 print(x // 3, x / 3 == x // 3, x % 3)
- What is printed? python n = int('9' 30) print(len(str(n + 1)), (n + 1) - 1030)
- What is printed? python print(5 & 3, 5 | 3, 5 ^ 3, ~5, 5 << 2, -5 >> 1)
- What is printed? python print(-1 & 0xFF, -8 >> 1, -1 >> 100, -9 & 7)
- What is printed? python print(1 << 64 == 264, (1 << 64) - 1 & 0xFFFF)