My program doesn't work. I know where the error is but I don't know how I can fix it.
The error message I get is: "Oops, try again. Your code looks a bit off--it threw a "string index out of range" error. Check the Hint if you need help!"
Why is the length of the string out of range? Shouldn't it be the last letter of the string? If I change it to len - 1 in line 3 it does what it is supposed to do but starting with the second last digit. Thank you for your help in advance
def digit_sum(n): string = str(n) length = len(string) su = 0 while length > 0: su += int(string[length]) length -= 1 return su a = 1234 digit_sum(a)