Why is this not working?! SOMEONE PLEASE HELP ME


#1

SOMEONE PLEASE HELP :I have no idea what the error means, but here is the code and the error:

n = [3, 5, 7]

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

Error message:Oops, try again. Did you create a function called print_list?


#2

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

why did you do n=x ? what does it mean?
it means you replace the list (n = [3, 5, 7]) with an undefined name(x) .

and you called the function inside that function(last line of code)


#3

@rcodeman: I added the n = x because adding that in made the code work for some people. As for my last line of code, what should I change it to? (or is it in the wrong place...?)


#4

I changed my code:

n = [3, 5, 7]

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

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


#5

You still called your function inside a function. You need to call the "print_list(n)" outside of its function. It is good practice to add a space between code once a function is done:

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

print_list(n)


#6

recursion is when you call a function within the function your calling..


#7

Thanks @ajaxrunner11363


#8