ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(1 + 2 * 3 ** 2 // 4 % 5, (1 + 2) * 3 ** 2 // 4 % 5)
- A. 5 6
- B. 4 1
- C. 1 1
- D. 5 1
Correct answer: D. 5 1
** comes first, then * // % from left to right. In 1 + 2 * 3 ** 2 // 4 % 5 the parts evaluate to 18 // 4 = 4 and 4 % 5 = 4, then 1 + 4 = 5. The parenthesised version gives 27 // 4 % 5 = 1.
More Python Programming questions
- What is printed? python print(1 == 1.0 and '1' != 1, [1, 2] == [1.0, 2.0], (1, 'a') == (1.0, 'a'))
- What is printed? python print(set([1, 2]) == {1.0, 2.0}, {1: 'x'}.get(1.0), {'1': 2}.get(1))
- What is printed? python print(2 63 - 1 == 9223372036854775807, (2 63) % 10, -2 63 // 10)
- What is printed? python print(str(10 15 / 10), str(10 16 / 10), 10 16 // 10)
- What is printed? python print('%.3g' % 0.0001234, '%.3g' % 123456.0, '%g' % 0.5)
- What is printed? python print(max('7', '10'), max(7, 10), min('7', '10'), '7' > '10')