ProgrammingVery hardProduct-company MCQ pattern

What is printed?

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

Correct answer: C. 1 2 1 1

** is right-associative, so 2 ** 2 ** 0 is 2 ** 1 = 2, and any number to the power 0 is 1. Unary minus binds looser than **, so -3 ** 2 is -9, and -9 % 5 is 1.

More Python Programming questions

Exams that ask this topic