ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(-(2 ** 3) ** 2, (-2) ** 3 ** 2, -2 ** -1, 0)
- A. -64 512 -0.6 0
- B. 65 -512 -0.5 0
- C. -64 -512 -0.5 1
- D. -64 -512 -0.5 0
Correct answer: D. -64 -512 -0.5 0
** binds tighter than unary minus on its left, so -(2 ** 3) ** 2 is -64. The exponent 3 ** 2 is 9, so (-2) ** 9 is -512, and -2 ** -1 is -(2 ** -1) = -0.5.
More Python Programming questions
- What is printed? python print(7 & 3 << 1, 7 & (3 << 1), 6 | 1 << 2, (6 | 1) << 2)
- What is printed? python print(~0, ~-1, -~0, ~~5, -~-5)
- What is printed? python print(max(map(int, '3 17 9'.split())), min(map(int, '3 17 9'.split())), sorted('3 17 9'.split())[-1])
- What is printed? python print(sorted(['1.10', '1.9', '1.10.1'], key=lambda v: tuple(map(int, v.split('.')))))
- What is printed? python print(sorted(['1.10', '1.9', '1.10.1']))
- What is printed? python values = [2.0, 2, '2'] print(len(set(values[:2])), len(set(values)), values[0] == values[1] == 2)