I dont know whats the problem can anyone help me?


#1



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


it says "Oops, try again. Does your purify function take exactly one argument (a list of numbers)? Your code threw a "'int' object is not iterable" error."


I thought it will work and it will remove all the odd numbers that are in the list.


def purify(numbers):
    y=[]
    if len(numbers)>1:
        for i in numbers:
            if i%2==0:
                y+=i
    else:
        if numbers%2==0:
            y+=numbers
    return y


#2

You can't add an int to a list by typing y += i.
You need to use the append attribute: y.append(i)

And you trying to divide the list by an int, that doesn't work also.

And these syntax errors lead you to an false end, and makes whole progress unnecessarily complex which I can't help in that complexity.

Therefore I want to share an elegant and simple solution with you:

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

#3

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