# I'm creating a program that adds each digit number, but I don't know how to correct the error.

Asked 2 weeks ago, Updated 2 weeks ago, 1 views

You are creating a program that adds each digit number.

In the first iteration of the function lot, we figure out the number of digits, and in the second iteration, when we put the number 7984 in x, for example, 7984, 798, 79, 7, and in the third iteration, if y is 7984, we subtracted the value of 798 by 10 and added the existing value of y. And if we add all of x[], we're going to get y back, and if y is greater than 10, we're going to do it again with n.

However, the index out of range error is not fixed. Please tell me how to modify it.

error python

2022-09-20 15:53

This is probably the most common Python code that adds up to a number of digits.

``````digit number = sum(map(int, str(number))))
``````
``````>>> sum(map(int, str(33)))
6
>>> sum(map(int, str(12345)))
15
``````

2022-09-20 15:53

## If you have any answers or tips

Popular Tags
python x 4520
android x 1589
java x 1455
javascript x 1363
c x 881
php x 682
html x 629
swift x 586
ios x 538
mysql x 397