Digit_sum function


#1

https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/digitsum?action=resume_content_item

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!:slight_smile:


#2

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.