for this, why doesnt my code (below) work?
def digit_summ(x):
total=0
for item in str(x):
total+= int(item)
return total
print digit_summ(87)
thanks!
for this, why doesnt my code (below) work?
def digit_summ(x):
total=0
for item in str(x):
total+= int(item)
return total
print digit_summ(87)
thanks!
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.