[Solved] Python Division Function [closed]


The divmod function does exactly what you want:

>>> a, b = divmod(9,5)

>>> a
1

>>> b
4

However, if you want to define your own function, this should work:

def divide(n1, n2):
    quotient = n1 // n2
    remainder = n1 % n2
    return (quotient, remainder)

The // operator represents integer division, and the % operator represents modulo (remainder).

>>> a, b = divide(9,5)

>>> a
1

>>> b
4

0

solved Python Division Function [closed]