15.4. I don't know what I did wrong?! Can anybody help me out?


#1



This is the excercise I am stuck at:
https://www.codecademy.com/courses/python-intermediate-en-rCQKw/0/4?curriculum_id=4f89dab3d788890003000096#


I have no idea what I did wrong, this is the error message I get when I run my code:
Traceback (most recent call last):
File "python", line 11, in
File "python", line 4, in digit_sum
TypeError: 'int' object is not iterable

I also get this error at the bottom of my screen:
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.


Replace this line with your code. 
This is my code: digits_sum = 0

def digit_sum(x):
    for number in x:
         strings = str(x)
    for item in strings:
        seperate_numbers = int(item)
    for digit in seperate_numbers:
        digits_sum += digit

print digit_sum(1234)


#2

here:

for number in x:

x is a integer, you can't loop over integers (integers are not iterable)

make sure that everything you need to calculate the digit_sum is inside the function (including declaring digits_sum)


#3

For the code above, I think the two steps are just flipping around with integers and strings. For example, strings=str(123)="123", and then you went back to the original step and turned seperate_numbers=int("123")=123, rather than 1,2,3

Good luck!


#4

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