Purify - Why Doesn't This Work?


#1



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

Traceback (most recent call last):
File "python", line 9, in
File "python", line 5, in purify
AttributeError: 'int' object has no attribute 'append'

What am Is going on to where it's wrong? I thought I was finally going to be able to crack a exercise by myself..


def purify(numbers):
    newnumb = 0
    for i in numbers:
        if i % 2 == 0:
            newnumb.append(i)
            print newnumb
    return newnumb
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
purify(numbers)
        



#2

this line:

newnumb.append(i)

you append i to a integer. Append works for list, not numbers. You could change your newnumb variable into a list:

newnumb = []