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


Continuing the discussion from 12 Printing out a list item by item in a function - error:


Here’s a printscreen of my code with the error included. I’m not really sure how to fix this. Any help is appreciated!
<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

<What do you expect to happen instead?>


Replace this line with your code.

<do not remove the three backticks above>


i want to know the answer too so please anyone else but me answer. ( sorry i couldn’t help you @nn210)

#Create your list
n = [3, 5, 7]

#define your function
def print_list(x):
#loop until the length of the argument **x**
    for i in range(0, len(x)):
#Print it out
        print x[i]
#Call your function
print print_list(n)


Thank you @bandit for your reply but sorry I still don’t understand. I’m now receiving a different error message from changing the indent of print print_list(n).


Haha well that’s because your print print_list should be on line 10 wih a space betwen the function and you don’t need to include a print statement.


@bandit I took out the print statement but it still didn’t work, so I added it back and moved print print_list to line 10. Am I having a serious dumb moment because this task has taken me the longest time to solve over anything so far, and it was supposed to be simple!


There should be no indentation for print_list(n)


Now I’m getting a different error. Sorry if I’m being frustrating!


Haha no not at all! debugging code is the fun part of programming :sweat_smile:

n = [3, 5, 7]

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

try this code format.


Problem is 2 for loops


Whey it worked!! Thank you so much!


If that was the answer you were looking for feel free to click the solution button beneath my reply :grinning:


when I use you codeI get the error:
“The body of your function should not contain references to ‘n’.”


Leave an empty line between print x[i] and print_list(n)


You don’t need to use two for loops. One is enough.
You also forget to return the x. Here is the working code:

n = [3, 5, 7]
def double_list(x):
    for i in range(0, len(x)):
        x[i] = x[i] * 2
# Don't forget to return your new list!
    return x

print double_list(n)


This gives me an error.


where’s your code? :grinning:


If you have this error " The body of your function should not contain any references to ‘n’" just remove first loop statement…


This worked for me, even though I had the original loop commented out. Odd.