12/18 Error: list index out of range


#1

I am not sure why my code isn’t correct I get 3, 5, & 7 printed out but it’s marking an x in the box. I tried to replace the “n” in len() with “x” but that just printed me out continuous 3, 5, & 7’s so I had to close my browser to get it to stop. I don’t know what I am doing wrong.

Here is my code.

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


#2

I receive an error list index out of range.


#3

The following works correctly, but without using n inside the function. We should use only the parameter, x which is a reference to n.

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

		
>>> n = [3, 5, 7]
>>> print_list(n)
3
5
7
>>> 

Be sure to use four spaces for indentation as that is what may be expected by the lesson checker.


#4

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