Variables, Types & Operators · Question 17 · Hard

Floor division by a float and a remainder with a negative divisor are printed together. What is the output?

print(7 // 2.0, 7 % -3)
  1. 3 1
  2. 3.0 -2
  3. 3.5 -2
  4. 3.0 1
Answer and explanation

Answer: B. 3.0 -2

Explanation: Floor division with a float operand still floors, but returns a float: 3.0. The remainder takes the sign of the divisor: 7 // -3 is -3, and 7 - (-3 × -3) = -2.

Previous: Booleans are used in arithmetic here. What does the snippet print? · Next: Five different operators appear in one expression. Following precedence rules…

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