Purify: Why isn't it adding to the list?


#1



For some reason, the code doesn't attach the even numbers onto the list.

Every time I run it I get:
Oops, try again. Your function fails on purify([4, 5, 5, 4]). It returns [] when it should return [4, 4].


What have I done wrong?


def purify(num):
    num = []
    even = []
    for i in num:
        if i % 2 == 0:
           even.append(num[i])
    return even

print purify([666, 5, 4, 2])


#2

Remove this line it is not doing anything in your code,

And change this line,

Remove the num[ ] so it should just be,

even.append(i)


#3

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