[issue41201] Long integer arithmetic

Rémi Lapeyre report at bugs.python.org
Fri Jul 3 08:40:48 EDT 2020


Rémi Lapeyre <remi.lapeyre at henki.fr> added the comment:

This is because you used the floating point division operator `/` instead of the integer division `//`:


def digitsum(num):
    digsum = 0
    tnum = num
    while tnum > 0:
        print("tnum = %d, digsum = %d" % (tnum,digsum))        
        digsum += (tnum % 10)
        tnum = int((tnum - (tnum % 10)) // 10)
    return digsum

gives the result you expect.


Please ask for help on StackOverflow or the python-help mailing list first as this bug tracker is for reporting bugs in the Python interpreter itself and not for general help with Python programming.

The various numeric operator are documented at https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex

----------
nosy: +remi.lapeyre

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41201>
_______________________________________


More information about the Python-bugs-list mailing list