"Traceback (most recent call last):
File "python", line 17, in
File "python", line 7, in digit_sum
IndexError: list assignment index out of range"
I am trying to do this using the method of % and // (modulo and floor division) described in the hint. I thought the problem might be that because n is changing inside the for loop, I could solve the problem by setting a fixed variable outside the loop for the length of n, but that did not help and I still get the same error message. Where am I going wrong?
def digit_sum(n): # Challenge version using modulo sum_of_digits = 0 # Set our var to zero to store the sum below digit =  # Set up var "digit" as an empty list # Need to set a variable that will stay fixed and store starting length of n: start_n_len = len(str(n)) for i in range(start_n_len): digit[i] = n % 10 # Take the ith digit from the right side and store it as digit[i] # Now we need to add this in a loop... sum_of_digits += digit[i] # ...and take the digit stored in digit[i] off of n # To do this, we will use // 10 n = n // 10 return sum_of_digits print digit_sum(1234)