12 Printing out a list item by item in a function - error


I dont understand why my code does not work. Here it is:

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

It returns an error message saying " It looks like you either didn't call print_list(n) or there is something wrong because 3 wasn't printed."

Any help is more than appreciated!


Well you didn't call print_list, you created this function but so far you didn't use it. Also have a look at this:

As indents are part of the syntax in python it is important that you display code as code and not as plain text.


Hi, thank you for your answer.
I tryied that but it didn't work either.

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

Printing out a list item by item in a function- error maximum recursion depth

Sorry, I changed x for n and worked, I don't really understand why.


As said see the link on how to format your code


And about the rest. Well what you enter at the () when calling the function is assigned to the variable in the () of the function definition. So in this case the list n gets assigned to the parameter x. Also you don't need a print before print_list as it doesn't return a value and has its own print statement inside.


Hi, thank you again.
I was trying to follow the instructions of the exercise since I have difficulty with programming. I actually don't understand much of what I do but I'm trying.
Thank you for your help.


If something is unclear you can for example test it here:
or see how it is executed here:
or just ask questions here.


Hi I had the same issue, the function wouldn't take "x" or "num" or whatever else I could think of as an argument. In the end I tried the "v" and that worked out... The instructions were somewhat misleading for this particular exercise. Instructions are usually remarkably clear otherwise.


Thank you for these links! They are very helpful for double checking that I actually know what's going on with the code.


Hello guys, I don't know what wrong in the following code:

Please can somebody help me on this


Even i had the same issue and this worked for me

n = [3, 5, 7]

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



This is what what I did and it worked

n = [3, 5, 7]

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

print print_list(n)


I don’t know what kind of problem you can call this but after making my code shorter it kind of worked. What I did is (as you can see from the screen shot that I posted earlier) I deleted the commented part from the code from line 2 to 4 and thus reduced the length of the code to 6 lines. What a frustrating thing. Even though the code was correct it didn’t used work. At last I got it correct. So I don’t think there is a need to change x to v or num or anything else…


thank you, you helped me figure out a simple error i made in my program.


you probably just have to delete the commented lines.


I had the same issue… no change to the code I wrote, just had to remove the existing comments, which shouldn’t have any affect at all.


That is because you didn’t really call that function to be used.
Your code should look like this:

n = [3, 5, 7]

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


I tried commenting the “scaffolding” out and was still getting the “the body of your function should not contain any references to n” error. Deleting that scaffolding fixed it. This lesson is bugged.


That did it for me, it is a bug. Thanks


you are missing calling for print for print_list(n)