ProgrammingHardTCS CodeVita · Infosys HackWithInfy · Product Company SDE

What does the following Python 3 code print? a, b = 18, 5 print(a // b, a % b, -a // b, -a % b)

  1. A. 3 3 -3 -3
  2. B. 3 3 2 -4
  3. C. 3 3 -4 2
  4. D. 3 3 -4 -2

Correct answer: C. 3 3 -4 2

Python's // floors toward −∞ and % takes the sign of the divisor, so −a//b rounds down and −a%b is non-negative. Output: 3 3 -4 2.

More Python Programming questions

Exams that ask this topic