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)
- A. 0 1 6 1
- B. 1 1 -6 -27
- C. 1 -1 -6 2
- 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
- What is printed? python print('%.3s|%5.1s|' % ('abcdef', 'xyz'))
- What is printed? python print('straße'.casefold() == 'strasse', 'straße'.lower() == 'strasse', 'Straße'.casefold())
- What is printed? python print('x'.removeprefix('xx'), 'hello'.removesuffix('llo'), 'abc'.removeprefix(''))
- What is printed? python print(str.maketrans('ab', 'xy', 'c'), 'abcabc'.translate(str.maketrans('ab', 'xy', 'c')))
- What is printed? python print(sorted(['10', '9', '100', '2']), sorted(map(int, ['10', '9', '100', '2'])))
- What is printed? python print(-7 // -2, 7 // -2 -2 + 7 % -2)