ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(1 + 2 * 3 ** 2 // 4 % 5, (1 + 2) * 3 ** 2 // 4 % 5)
  1. A. 5 6
  2. B. 4 1
  3. C. 1 1
  4. 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

Exams that ask this topic