4.digit_sum


#1

what's the problem with my code?:
def digit_sum(n):
for x in str(n):
return int(x) + int(x)
it returns "Oops, try again.
Your function fails on digit_sum(434). It returns 8 when it should return 11.
"

`


#2

a function ends the moment a return keyword is reached, try creating a variable (call it total if you like), set it to 0, then add int(x) to total, and then return total

Make sure to do the indent right, the whole for loop must run


#3

it stile dose not work:

def digit_sum(n):
    c = 0
    w = str(n)
    for x in w:
        c += int(x)
        return c

Oops, try again.
Your function fails on digit_sum(434). It returns 4 when it should return 11.


#4

it is a lot better, except the return keyword is now reached in the first run of the loop. Maybe you should indent it differently so the whole loop can run?


#5

thanks!