Purify


#1



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

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

When I run this script in Python IDLE it outputs [] correctly for this error, or any other variation I try. When I copy and paste my script into this web site it does not go through. I start my scripts like this all the time, just wondering if I am formatting something wrong? Thanks


#comments are what I run in IDLE, I comment them out in Codecademy before running script.

#import random

#num = [random.randint(1, 100) for i in range(100)]
evens = []
def purify(num):
    for i in range(len(num)):
        if num[i] % 2 == 0:
            evens.append(num[i])
    return evens
    
#purify(num)


#2

the exercise test multiply list on your function, it is important to make the list empty at the start of the function:

def purify(num):
    evens = []

otherwise leftover from earlier runs might stick around. Sure, if you run the program from start each time this isn't a problem, but the exercise only test what is inside your function


#3

Oh my gosh... sorry. Minor oversight. It worked after placing it inside. Will include variables inside the function for codecademy. Thank you for the tip.