can someone please explain the logic behind this code …

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

cos this is what i wrote initially

```
def digit_sum(n):
return digit_sum(n)
```