# Printing out a list item by item in a function

#1

do not know what is wrong error message reads

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

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

print_list(x)``````

#2

If you use the placeholder x in your def line, you need to be consistent throughout the method. Right now the method does not know what n is, so it confuses it.

Next, your print_list(x) line should be outside of the method and should call n instead of x.

#3

That worked, thank you very much

#4

Hi, I have this problem:

Error

Oops, try again. The body of your function should not contain any references to 'n'

Code 1

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 2

script.py

1
2
3
4
5
6
7
8
9
10
11
n = [3, 5, 7]
for i in range(0, len(n)):
print n[i]

def print_list(x):
for i in x:
print x[i]

print_list(n)
3
5
7
Traceback (most recent call last):
File "python", line 10, in
File "python", line 8, in print_list
IndexError: list index out of range

Code 2
n = [3, 5, 7]

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

def print_list(x):
for i in x:
print x[i]

print_list(n)

could anyone help me? i'm lost

#5

Your Code 1 looks correct. However, I found you need to get rid of the starter code this exercise provided. So if you remove:

``````for i in range(0, len(n)):
print n[i]``````

then you'll pass the exercise. Even when this portion is commented out, during submission it reads this and gave me the same error.

Also make sure your other code is indented correctly:

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

print_list(n)``````

#6

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