Purify seems to work but still returns error?



Oops, try again.
Your function fails on purify([1]). It returns [2, 4, 6, 8] when it should return [].

I'm receiving this error message, despite the fact that the console is printing what looks to me like the correct response regardless of what input I give it. Can anyone help diagnose my issue?

numbers2 = []

def purify(numbers):
    for l in numbers:
        if l % 2 == 0:
    return numbers2
print purify([2,3,4,6])


remove the last line


That didn't seem to work.


weird probably a bug maybe?


I think you should put the numbers2 list inside your purify function, it worked for me that way

def purify(nums):
    ret = []
    count = 0
    for n in nums:
        if n % 2 == 0:
        count += 1
    return ret

Hope it works for you :slight_smile:


Ugh, can't believe it was something silly like that. Thanks, that fixed the issue.


Do you mind explaining why this works with or without the count = 0 variable?


since I just did the count variable for debugging reasons it works without it also. As you can see it just counts how many times the for loop gets executed.


Try this! It worked for me:

def purify(var):
new_var = [ ]
for item in var:
if item % 2 == 0:
return new_var

def purify(num):
    ans = []
    for x in num:
        if(x%2 == 0):
    return ans

print purify([1,2,3,4,5,6,7,8,9])