Rémi Lapeyre <[email protected]> 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 <[email protected]>
<https://bugs.python.org/issue41201>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com