ProgrammingVery hardTCS NQT · Accenture

What is printed?

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

Correct answer: C. 3 7

-7 // -2 floors 3.5 to 3. For 7 // -2, floor division gives -4, and 7 % -2 is -1, so (-4) * (-2) + (-1) = 7. The identity a == (a // b) * b + a % b always holds.

More Python Programming questions

Exams that ask this topic