4/15 digit_sum


Can someone explain me:
1- What am I doing wrong here as the result is as expected
2- What should I do instead (without giving the solution... that is, explain me in plain text)

Here is the code I wrote:

num = raw_input('number:')
def num_into_list(num_integer):
    for i in num_integer:
    return liste
def digit_sum(lst):
    for i in lst:
    return sul
z = num_into_list(num)
print digit_sum(z)


If the result is as expected, then what is the problem?
(I'm sure I can find out by running your code in the exercise, but question-asking is essentially how you start debugging on your own anyway so might as well start with that.)


The problem is that codecademy doesn't accept my code; the error message is:"Oops, try again. Does your digit_sum function take exactly one argument (a positive integer)? Your code threw a "'int' object is not iterable" error."
Sorry I forgot to mension that!


So the submission test called your function and got that error.
But when you call your function, you don't.

That suggests that you are calling it differently from the submission test, right? How should it be called?


OOOwwww.... thanks !
So it's just that I think differently from the 'submission test'... I am going to try another way. Calling a function that has an argument of a different kind right (i.e digit_sum should have an argument that is not a list) ?


Right, your function should expect one argument, an integer (an instance of the int type)


Thanks a lot, I was stuck there and I didn't know why !


hahaha from 15 lines down to... 6 !!!!
Thanks codecademy an thanks a lot ionatan :smile:


I ended up with three lines via map.

 def digit_sum(n):
     o = sum(list(map(int, str(n))))
     return o

Edit: figured out the indentation in the forum…