Printing out a list item by item in a function


#1

Printing out a list item by item in a function

My code is:

n = [3, 5, 7]

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

print_list(n)

I get the message: Oops, try again. The body of your function should not contain any references to 'n'

and I get in the console: 3
5
7
3
5
7
None

That is incorrect.

Could somebody help please?


#2

Can I have the link to this exercise?


#3

the idea was to use this loop:

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

and place it inside the function and modify it. You wrote a new loop, that is fine, but then remove this loop.

i agree with kyleaw, the exercise url would be very useful


#4

found it


#5

then it seems i was right, the loop provided should have been used in the function. Of course it is then allowed to write a new loop, but then the old one (the one outside the function) has to be removed


#6

The first "FOR" isn't need it.
Use only the "DEF" statement and you'll be all good :smiley:


#7

Thank you to everybody. It is working now.


#8