0

Code is supposed to sum all numbers given by user input until only a single digit number remains.

Input 19991229 should result in 6, but I'm getting 33 instead, as if the two remaining numbers aren't summed.

Here's the code:

b_d = input("enter birthdate")
digits  = []
for d in b_d:
    digits.append(int(d))
print(digits)
life  = 0
while (sum(digits)) >= 10 :
    for x in digits:
        life += x
        digits.remove(x)
            
        
print(life)

this resolves the issue, but it's too ad hoc and doesn't work on all cases:

r = 0        
for y in str(life):
    r += int(y)
print(y)
  • 1
    Does this answer your question? [How to remove items from a list while iterating?](https://stackoverflow.com/questions/1207406/how-to-remove-items-from-a-list-while-iterating) – Random Davis Feb 09 '23 at 21:49

0 Answers0