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 <1593780048.39.0.875094434551.issue41201@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2020-07-03 12:40:48remi.lapeyresetrecipients: + remi.lapeyre, David Srebnick
2020-07-03 12:40:48remi.lapeyresetmessageid: <1593780048.39.0.875094434551.issue41201@roundup.psfhosted.org>
2020-07-03 12:40:48remi.lapeyrelinkissue41201 messages
2020-07-03 12:40:48remi.lapeyrecreate