4. digit_sum


#1

https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/0/4?curriculum_id=4f89dab3d788890003000096

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
digit_sum(434)

#2

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


#3

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


#4

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.


#5

What does the above line do?

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

Great job :).


#6