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


#1



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


Error : Your function caused the following error: maximum recursion depth exceeded


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


#2

You're supposed to be printing x[i], not the function itself. Then call the function. Your function went to call on your function which calls on your function, etc. (maximum recursion exceeded)


#3

still doesn't work

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

error : print_list should take exactly one argument (a list to print).


#4

You're still calling the function inside the function. You also don't need to print it since it's built into the function. Take "print print_list(n)" out of the function. Just call print_list(n) after the function is done.


#5

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

it still doesn't work


#6

x[i] not x(i). You're basically saying array[index] where index is going to count up until it hits the end of the array.


#7

It is working all fine now. Thanks for the help.


#8

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