ProgrammingModerateTCS NQT · Infosys

What is printed?

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

Correct answer: A. 3 -3

For both signs a == (a // b) * b + a % b holds, so the first value is 3 and the second is -3. Floor division of -3 by 2 is -2, and -3 % 2 is 1, which gives -4 + 1 = -3.

More Python Programming questions

Exams that ask this topic