I am wondering why the code I wrote wont work. If I manually (without using a for loop) enter the instructions in python it seems to work fine...
What I am attempting to do with the code is:
To convert my int to str so I can access the different numbers and then use a for loop to go one by one adding the values which I am converting back into int
I appreciate any insight! Cheers
The error message I get is : "string indices must be integers, not str"
Replace this line with your code. def digit_sum(x): y = str(x) result = 0 for z in y: result += int(y[z]) return result