Printing out a list item by item in a function


#1

This is my code,

n = [3, 5, 7]

def print_list(x):
for y in range(0, len(n)):
print x[y]

print_list(n)

I've done exactly what it says to do, but I get the error message

Oops, try again. Your function caused the following error: list index out of range


#2

Also in the editor it does exactly what it's supposed to, but I still get this error.


#3

Your function works for me !!!

n = [3, 5, 7]

def print_list(x):
    for y in range(0, len(n)):
        print x[y]

print_list(n)

#4

the exercise will test different lists on your function, to it works properly. But in your for loop you take the length of the list you created (len(n)), so if the exercise decide to test a list with two items, you have a problem

I would, check the length of the list passed into the function (len(x))