Message372929
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 |
|
Date |
User |
Action |
Args |
2020-07-03 12:40:48 | remi.lapeyre | set | recipients:
+ remi.lapeyre, David Srebnick |
2020-07-03 12:40:48 | remi.lapeyre | set | messageid: <1593780048.39.0.875094434551.issue41201@roundup.psfhosted.org> |
2020-07-03 12:40:48 | remi.lapeyre | link | issue41201 messages |
2020-07-03 12:40:48 | remi.lapeyre | create | |
|