Purify error


#1



PURIFY
https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/2


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


Why don't this code work?


def purify(listofnum):
    new = []
    for index, element in enumerate(listofnum):
        if element % 2 != 0:
            new.append(element)
    return new


#2

the remainder of even numbers is zero, the remainder of odd numbers is one

Your if condition evalutes to true for odd numbers. You want a list with the even numbers


#3

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