[issue41201] Long integer arithmetic

David Srebnick report at bugs.python.org
Fri Jul 3 08:26:22 EDT 2020


New submission from David Srebnick <srebby at gmail.com>:

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))

----------
messages: 372925
nosy: David Srebnick
priority: normal
severity: normal
status: open
title: Long integer arithmetic
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41201>
_______________________________________


More information about the Python-bugs-list mailing list