Digit_sum function


for this, why doesnt my code (below) work?

def digit_summ(x):
for item in str(x):
total+= int(item)
return total

print digit_summ(87)


By default, a function returns None at the end of the function. If we want to return something else at the end of the function, we can use the return keyword.

Given return is the last thing a function does, when a return keyword is reached, the function ends

so your function ends in the first iteration of the loop, that can’t be right if you want to calculate the sum.