Hello! I write this code:

```
def digit_sum(n):
res = 0
ints = []
if n >= 0 and n - float(n) == 0:
n = str(n)
i = 0
in1 = 0
while i != len(n) - 1:
ints.append(n[i])
i += 1
while in1 != len(ints) - 1:
res = res + ints[in1]
in1 += 1
else:
print res
```

and got this message:

"list index out of range error"

Where I made a mistake? I absolutely don't understand how to write this program. Help me, please if you can.