ProgrammingHardProduct-company MCQ pattern

What is printed?

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

Correct answer: D. -3 -4 -3 -4

int() truncates toward zero, while // floors toward minus infinity, so -7 / 2 gives -3 under int but -4 under //. The same split happens for 7 / -2.

More Python Programming questions

Exams that ask this topic