Code works in idle but not on codecademy


#1


Practice Makes Perfect Python

When I run my code into the console, it runs perfectly but the editor keeps giving me this error message:
"Oops, try again. Your function fails on digit_sum(434). It returns 22 when it should return 11"


a = []
def digit_sum(n):
     n = str(n)
     total = 0
     for letter in n:
          a.append(int(letter))
     for number in a:
        total += number
     return total


#2

You don't need first for loop, but if you are using it you need to put your empty list inside function