I I do not understand why this code is not working

Define a function called purify that takes in a list of numbers, removes all odd numbers in the list, and returns the result.
For example, purify([1,2,3]) should return [2].

x = [1,2,3,4,5,6,7,8]
def purify(x):
q =[]
for n in x:
if n%2 == 0:
return q

I get the error

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


You are appending a list to the list, rather than a value.



My bad. Thank you so much.


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