Variables, Types & Operators · Question 8 · Medium

Floor division and remainder are applied to a negative number. What is the output?

print(-17 // 5, -17 % 5)
  1. -3 -2
  2. -4 -2
  3. -4 3
  4. -3 3
Answer and explanation

Answer: C. -4 3

Explanation: // rounds down towards negative infinity, so -17 // 5 is -4, not -3. The remainder takes the sign of the divisor: -17 - (5 × -4) = 3.

Previous: An integer is added to a float. What does Python print for the sum? · Next: Unary minus meets the power operator, with and without brackets. What does…

Practise variables, types & operators

Try a fresh set of variables, types & operators questions with an explanation after every answer, free and without signing up: Variables, Types & Operators practice. Or sit a full placement mock test.

More variables, types & operators questions

More python practice

Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge