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.

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

Popular Tags

© 2022 pinfo. All rights reserved.