4. Digit_Sum: Not sure what is wrong


#1



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

I used Textwrangler on my mac to complete this program step by step and it worked. I then copy pasted my code into the codecademy python interpreter, but I get an error message saying "Your function fails on digit_sum(434)" even though the program produces the correct sum! When I run the code on TextWrangler, no error messages pop up.

I am not sure what I'm doing wrong or if this is just a bug. Any help would be appreciated.


def digit_sum(n):

    #convert n into a string
    n = str(abs(n))
    result = []
    new = []
    
    #add the characters of the string into an empty list, result
    for letter in n:
        result.append(letter)
        
    #convert the items in result into integers
    for digit in result:
    	digit = int(digit)
        new.append(digit)
        print digit,
    print result
    print new
    print sum(new)


#2

It's telling you that when you call 434 on the function digit_sum(), it doesn't give the right output, say 11.

Check your loop.