Purify


#1



I can't understand why my code on purify doesn't run..


This is my code:
def purify(numbers):
new =[]
for n in numbers:
if n % 2 == 0:
new.append(n)
return new
else:
return new

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


Replace this line with your code.


#2

With indentation:

def purify(numbers):
     new =[]
     for n in numbers:
          if n % 2 == 0:
             new.append(n)
             return new
         else:
               return new

#3

for displaying indention check here:

uhm.. a function ends the moment a return keyword is reached, so you might want to think about changing the position of the return


#4

I got my mistake, there was no need of else statement.
simply return new after the if condition works well