12. printing out a list item by item in a function


#1

im getting what i think is an incorrect error code

n = [3, 5, 7]

for i in range(0, len(n)):
print n[i]

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

keeps saying i have a reference to n in the body of my function


#2

Can't reproduce what you describe because there's no link to the exercise and your formatting is broken. Keep in mind when asking questions that you have to provide a way to reproduce what you describe.
However, it is probably reacting to the loop that is outside your function


#3

yeah i removed the loop at the start and it worked just fine, i had assumed that the lesson wanted me to compare the function output to that of the existing loop so i left it in there. also i had just copied the code from my other screen, didnt notice the formatting had gone missing.


#4

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