Integer math question

Sean Ross sross at connectmail.carleton.ca
Sat Jan 3 20:05:09 CET 2004


Here's an interactive Python example to help clarify the previous response:

>>> a = 5
>>> b = 10
>>> q , r = divmod(a,b)
>>> q
0
>>> r
5
>>> a = -a
>>> a
-5
>>> q , r = divmod(a,b)
>>> q
-1
>>> r
5
>>> b*q + r    # division algorithm
-5
>>> -5 == a
True
>>>





More information about the Python-list mailing list