Message372925
The following program is one way of computing the sum of digits in a number. It works properly for the first case, but fails for the second one.
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
print(digitsum(9999999999999999))
print(digitsum(99999999999999999)) |
|
Date |
User |
Action |
Args |
2020-07-03 12:26:22 | David Srebnick | set | recipients:
+ David Srebnick |
2020-07-03 12:26:22 | David Srebnick | set | messageid: <1593779182.53.0.05415381128.issue41201@roundup.psfhosted.org> |
2020-07-03 12:26:22 | David Srebnick | link | issue41201 messages |
2020-07-03 12:26:22 | David Srebnick | create | |
|