Purify


#1


https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/2/2?curriculum_id=4f89dab3d788890003000096#

I got an error code that says: "Your function crashed on [1] as input because your function throws a "'NoneType' object is not iterable" error.". I obviously did something wrong, but I do not know what that is can anyone help me plz?


I expected it to append x to list2 if x was an even number


def purify(listonum):
    listonum = []
    list2 = []
    for x in listonum:
        if x % 2 == 0:
            list2.append(x)
            return True
        else:
            return False


#2

When you write listonum = [], you're setting the variable to an empty array, regardless of what parameters are there.
I understand you're trying to convert to a list though.

To fix this, try changing that line to listonum = list(listonum).


#3

def purify(listonum):
listonum = list(listonum)
list2 = []
for x in listonum:
if x % 2 == 0:
list2.append(x)
return True
else:
return False

My code now looks like this, but I get an error code: Your function crashed on [1] as input because your function throws a "'bool' object is not iterable" error.


#4

You should be returning your new list "list2", not a True or False


#5

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