Back to questions
JuniorTheoryCommon
What does the program print?
print(7 / 2, 7 // 2, -7 // 2, -7 % 3)3.5 3 -4 2
- Expecting
-7 // 2to be-3, as if//dropped the fraction://rounds down toward minus infinity, so-3.5becomes-4. - Expecting
-7 % 3to be-1: in Python the remainder takes the sign of the divisor, so it is2, since-7 // 3is-3and-3 * 3 + 2is-7.
- What does
7 % -3evaluate to, and why? - Why does
6 / 2print3.0rather than3?