In general, when an integer n is divided by an integer d to obtain an integer quotient q and an integer remainder r, the numbers are related as follows: n = dq + r. Python requires the integer remainder of an integer division by a positive integer to be positive, which agrees with the mathematical definition of modulus in number theory. When -7 is divided by 10, the only way to achieve this is for the remainder to be 3 and the quotient to be -1 because -7 = (10)(-1) + 3.
Comment
Thank you!
Parent comment
In general, when an integer n is divided by an integer d to obtain an integer quotient q and an integer remainder r, the numbers are related as follows: n = dq + r. Python requires the integer remainder of an integer division by a positive integer to be positive, which agrees with the mathematical definition of modulus in number theory. When -7 is divided by 10, the only way to achieve this is for the remainder to be 3 and the quotient to be -1 because -7 = (10)(-1) + 3.