Predict the output
What does this print?
print(-7 // 2, int(-7 / 2), 7 // 2)Choose an answer, then open Show answer below to check it.
Show answer
Answer: A -4 -3 3
Right: floor division rounds down; int() of the float truncates toward zero.
The two rules only disagree for negative results, which is exactly where the question's 'toward zero' rule matters.
Why not the others?
- B -3 -3 3. Floor division rounds toward negative infinity, giving -4.
- C -4 -4 3. int(-3.5) truncates toward zero, giving -3.