Why am I getting error, when my code does what it is supposed to do, I get my result, 10, printed on the screen, but it tells me I have an error and doesnt let me continue to the next part???
Here is my code:
def digit_sum(n): n = str(n) one = n[:1] two = n[1:2] three = n[2:3] four = n[3:4] n = int(one) + int(two) + int(three) + int(four) return n print digit_sum(1234)
I tried for hours to use a for loop instead, but Im doing something wrong…and when I look at the Codecademy solution to see how they did it, they gives the second(hard) solution…
Can you help me with the simpler solution they are asking for, where they aks us to convert the integer to a string with str(), iterate over it, and turn the substrings back into integers with int() to do the addition.