4. digit_sum



Hi, I'm stuck in this activity.
Well, I think console window typed the correct answer, though there was still an error that says 'Your function fails on digit_sum(434). It returns None when it should return 11. ' What is wrong?

Oh, here is my code:

def digit_sum(n):
    inte = str(n)
    results = list(map(int, inte))
    b = sum(results)
    print b


It is because your function doesn't return anything.
return the value instead of printing it


It worked, thank you!
And another little question. If I create a function, do I need to return the result?


It depends on you.what do you want from that function.it's not compulsory to have a return statement but it's most useful.for example you can store the returning value instead of just printing it.

if you use return in your function then call the function like

print function_name()

It'll print the returning value.


What does the above line do?

I'm not sure how I would have understood to use this map() by myself, hmm.

Great job :).