ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
print(7 // -2, -7 // 2, 7.0 // -2, -7.0 % 2)
  1. A. -3 -4 -3.0 1.0
  2. B. -4 -4 -4.0 2.0
  3. C. -4 -3 -4.0 1.0
  4. D. -4 -4 -4.0 1.0

Correct answer: D. -4 -4 -4.0 1.0

Both // and % use floor semantics in Python: the quotient rounds toward minus infinity, and the remainder takes the sign of the divisor, so -7.0 % 2 is 1.0.

More Python Programming questions

Exams that ask this topic