ProgrammingHardTCS NQT · Infosys

What is printed?

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

Correct answer: A. 1 1 1 8

** binds tighter than %, so each expression uses 3 ** 2 = 9 as the modulus. -10 % 9 is 8, because the result takes the sign of the divisor.

More Python Programming questions

Exams that ask this topic