12. Printing out a list item by item in a function. "The body of your function should not contain any references to 'n'" error


#1



This is the exercise in which I am stuck: Printing out a list item by item in a function.


When I run this code, I get the error message: "The body of your function should not contain any references to 'n'". As far as I can tell, there are no references to 'n' anywhere in my function.
This is my code:
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV

n = [3, 5, 7]

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


#2

You have a reference to n right there. You should not need that first for statement. Instead remove it, and feed the list to the function. print_list(n)


#3

I did this and it worked, thanks.

n = [3, 5, 7]
def print_list(x):
    for o in range(0, len(x)):
        print x[o]
for i in range(0, len(n)):
    print_list(n)

#4

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