It seems that my code contains an infinite loop which I have failed to recognize for a whole afternoon.

I have already went through other discussion about this task, so I am not looking for a solution to get to the next session. If anyone has an idea about where I failed please don't hesitate to share your insight. Thank you.

```
def digit_sum(n):
digitsum = 0
p = 1
while n % (10**p) > 0:
digitsum += (n % (10**p) - n % (10**(p-1))) / 10**(p-1)
p += 1
return digitsum
```