why my code is not working??Can somebody explain this

output is coming wrong

i expect to get answer

```
def digit_sum(n):
digits=len(str(n))
i=1
while i<=digits:
var=0
nth=n//10**(digits-i)
remainder=n%10**(digits-i)
var+=nth
n=remainder
i+=1
return var
n=input("Enter positive integer: ")
print digit_sum(n)
```