This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author remi.lapeyre
Recipients David Srebnick, remi.lapeyre
Date 2020-07-03.12:40:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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
Date User Action Args
2020-07-03 12:40:48remi.lapeyresetrecipients: + remi.lapeyre, David Srebnick
2020-07-03 12:40:48remi.lapeyresetmessageid: <>
2020-07-03 12:40:48remi.lapeyrelinkissue41201 messages
2020-07-03 12:40:48remi.lapeyrecreate