ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(1 + 2 * 3 ** 2 // 4 % 5, (1 + 2) * 3 ** 2 // 4 % 5, -2 ** 2, (-2) ** 2)
  1. A. 5 1 -4 4
  2. B. 5 1 -8 4
  3. C. 6 1 -4 4
  4. D. 5 4 -4 4

Correct answer: A. 5 1 -4 4

** binds tightest, then *, // and % from left to right, and + last. So 2 * 9 // 4 % 5 is 4 and 1 + 4 is 5. -2 ** 2 is -(2 ** 2), and (-2) ** 2 is 4.

More Python Programming questions

Exams that ask this topic