I honestly could not figure this one out for the life of me. I thought the “solution” would help me figure out what it was asking for, but it seems that most people in the forums used the “converting the integer into a string” method. can someone explain the solution’s method instead?

“Write a function called `digit_sum`

that takes a positive integer `n`

as input and returns the sum of all that number’s digits. For example: `digit_sum(1234)`

should return `10`

which is `1 + 2 + 3 + 4`

. (Assume that the number you are given will always be positive.)”

```
def digit_sum(x):
total = 0
while x > 0:
total += x % 10
x = x // 10
print x
return total
```

I understand the method using strings but what is going on here? I’d just like a step by step explanation