ProgrammingHardTCS NQT · Infosys

What is printed on the second line?

What is printed on the second line?
a, b = -13, 4
print(a // b, a % b, a // b * b + a % b == a)
print(int(a / b), int(-3.25), -3.25 // 1)
  1. A. -4 -3 -4.0
  2. B. -3 -3 -3.0
  3. C. -3 -4 -4.0
  4. D. -3 -3 -4.0

Correct answer: D. -3 -3 -4.0

int() truncates toward zero, so int(-3.25) is -3, while floor division of -3.25 by 1 rounds down to -4.0. Mixing int() with // is a common source of mistakes.

More Python Programming questions

Exams that ask this topic