Practice makes perfect: digit_sum (this should


#1



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


I get this error message: Oops, try again. Does your digitsum function take exactly one argument (a positive integer)? Your code threw a "'int' object is not iterable" error._


I was expecting it would work...


def digit_sum(n):
    count = 0
    for digit in n:
        digit = int(digit)
        count += digit
    print(count)
n = raw_input("Enter digits: ")
digit_sum(n)


#2

here:

 for digit in n:

n contains an integer, integers are not iterable.


#3

Thank you but I still don't get it, sorry. Doesn't "raw_input" automatically converts anything in string? ...


#4

yes, it does. But the exercise is also going to call your function passing integers as argument


#6

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