Digit_sum


#1



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.


My code can meet the function requirement and output the right answer. Just don't why always showed error.


def digit_sum(n):
    m=[]
    for i in n:
        i=int(i)
        m.append(i)
    print m
    return sum(m)
n=raw_input("positive number: ")
print digit_sum(n)


#3

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


#6

You were errored probably because you used the same variable "n" in both starting digit_sum and in raw_input.

Change the variable of raw_input to something else along with the variable in print digit_sum()


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.