ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(7 % 3 ** 2, (7 % 3) ** 2, -7 % 3 ** 2, 2 * 3 ** 2 % 4)
  1. A. 7 1 2 4
  2. B. 1 1 2 2
  3. C. 7 2 2 2
  4. D. 7 1 2 2

Correct answer: D. 7 1 2 2

** binds tighter than %, so 7 % 3 ** 2 is 7 % 9 = 7. Parentheses change the result to 1, and -7 % 9 is 2 because the remainder takes the divisor's sign.

More Python Programming questions

Exams that ask this topic