Find the division remainder of a number

Solution 1:

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.

Solution 2:

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)

Solution 3:

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)

Solution 4:

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)