12/18 Please help

I see that this code worked for other people but when I try it, it gives me the error “My function caused the following error: list index out of range” Please help.

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

Look at your function…

Double Check Your Code:

def print_list(x): 
      for i in range(0, len(n)):  #something is wrong on this line
          print x[i]

n = [3, 5, 7]

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

print print_list(n)

Try this it worked for me

3 Likes

you have to replace len(n) with len(x)
for i in range(0, len(x)):
:grinning:

Hi everyone! I’m having the same trouble. That’s 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 print_list(n)

and I’m getting this error message “Oops, try again. The body of your function should not contain any references to ‘n’”

Can’t get what’s wrong with the code:(

Hi tagace65163,

Replace the word “scaffold” with “template” and then try re-reading the directions. It should make a lot more sense then.

Added hint: Lines 3 and 4 are technically considered in your body at this point.

If u have comment in your solution, remove it. should be help

Hi,

You should remove

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

Also, no need to say

print print_list(n)

as printing is included in your function print_list(n) already.

just finish on

print_list(n)

2 Likes

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

4th line must be indented 3 times from the start

Hi there,
I do it exactly like that, but it keeps throwing me an error: print_list should take exactly one argument (a list to print).

x = [3, 5, 7]
def print_list(x):
for i in range(0, len(x)):
print x(i)
print print_list(x)
I have no idea what exactly I am doing wrong :frowning:

I have the same error.
If you replace len(x) with 3 the error is:
Oops, try again. Your function caused the following error: list index out of range

the site tests your function with its own list,
so if you hardcode 3 into your for function,
you’ll break the test the site tests your code with.

you have on line 4, your print is in parenthesis rather than brackets * sorry for the superbly late response

There is no need to do “print print_list(n)”
n = [3, 5, 7]

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

print_list(n)