Printing out a list item by item in a function


#1



Hello,
This is my code for the excercise.

n = [3, 5, 7]

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

It resulted with the following error:
"Oops, try again. Your function caused the following error: list index out of range"

I am not sure what I did wrong, can anyone help?


#2

The variable n is global variable.
Our function can take any variable as argument (here a list).
The function have x as parameter and It can have any length.

Look at this line of code..
for i in range(0, len(n)):


#3

Thank you so much!

n = [3, 5, 7]

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

print_list(n)


#4

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