Printing out a list item by item in a function


#1



https://www.codecademy.com/en/courses/python-beginner-nzzVa/3/1?curriculum_id=4f89dab3d788890003000096#


Oops, try again. Your function caused the following error: maximum recursion depth exceeded while calling a Python object


Have tried to find an answer on forums, can not find one. I have run into the same error quite a few times in these exercises, could someone explain what it means so I have an idea of what to do for next time?

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


#2

You are very close to the solution, but keep in mind that you are taking an input parameter in the function you just created,x, this is so the function can take different lists as input. what you're doing is asking for what list should be printed, and then proceed to work with X and N. Try swapping the N variables in your function for x'ses :slight_smile:


#3

Tried that, doesn't work, keeps repeating the same error over and over; Oops, try again. Your function caused the following error: maximum recursion depth exceeded while calling a Python object


#4

your function call:

print_list(n)

is inside your function, causing the function to endless call itself (Recursion), sort of like an infinity loop


#5

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

print_list(n)

Tried doing this. Now receiving a new error: Oops, try again. Your function caused the following error: list index out of range

What would this mean, and how do I work with the code now?


#6

@systemsurfer07914 covers this problem, so i thought i wouldn't have to cover it again?


#7

Oh, my mistake, sorry.

EDIT: Solved, thanks for the help.


#8

Can you please share your solution?


#9

he can't, it is against the guidelines, if you need help, please make a new topic


#10