Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the division remainder of a number

People also ask

What is the formula to find the remainder?

In the abstract, the classic remainder formula is: Dividend/Divisor = Quotient + Remainder/Divisor.

What is the remainder when 599 is divided by 9?

The quotient (integer division) of 599/9 equals 66; the remainder (“left over”) is 5.

What is the remainder of 3300 divided by 19?

The quotient (integer division) of 3300/19 equals 173; the remainder (“left over”) is 13.


you are looking for the modulo operator:

a % b

for example:

>>> 26 % 7
5

Of course, maybe they wanted you to implement it yourself, which wouldn't be too difficult either.


The remainder of a division can be discovered using the operator %:

>>> 26%7
5

In case you need both the quotient and the modulo, there's the builtin divmod function:

>>> seconds= 137
>>> minutes, seconds= divmod(seconds, 60)

26 % 7 (you will get remainder)

26 / 7 (you will get divisor, can be float value)

26 // 7 (you will get divisor, only integer value)


If you want to get quotient and remainder in one line of code (more general usecase), use:

quotient, remainder = divmod(dividend, divisor)
#or
divmod(26, 7)