Would you know if this is a possible bug


#1

I have implemented this approach below::

x_list = []
def digit_sum(x):
    #treat x as a list
    x_string = str(x)
   
    for i, char in enumerate(x_string):
        x_list.append(int(char))
     
    print x , x_list , sum(x_list)
    return sum(x_list)     
     
digit_sum(434)

given the above code, I correctly returned 11 but I have this error:

Oops, try again. Your function fails on digit_sum(434). It returns 22 when it should return 11

Would you know if this is a possible bug or I just made a real mistake? I run my code in jupyter and it runs as expected.

Thanks!


DIgit_sum-Oops, try again. Your function fails on digit_sum(434). It returns None when it should return 11
#2

Not a bug, and not a mistake, per se. However, not what the lesson checker is expecting. Because you created the list outside of the function, and the code ran when you submitted it, the list already contains three elements when the SCT calls the function.

To fix this, move that statement to inside the function so the list gets created anew every time the function is called.