[issue41201] Long integer arithmetic

2020-07-03 Thread Christian Heimes


Change by Christian Heimes :


--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41201] Long integer arithmetic

2020-07-03 Thread Rémi Lapeyre

Rémi Lapeyre  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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41201] Long integer arithmetic

2020-07-03 Thread David Srebnick


New submission from David Srebnick :

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())
print(digitsum(9))

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

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com