12. Printing out a list item by item in a function


#1


Hi Everyone,

I seem to be getting the following error with the below code

Oops, try again. It looks like you either didn't call print_list(n) or there is something wrong because 3 wasn't printed.

Not sure what I am doing wrong

Thanks in advance!

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


#2

you need to add a function call, otherwise the function won't execute


#3

Thanks the below code worked:

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

However, just had a question on the indentation before - print print_list(n) . Why isn't this indented ?


I tried the above code i got error Oops, try again. Make sure to print the second element of the list using bracket notation
#4

its indented, with zero spaces.

if you where to indent it with 4 spaces, it would be part of the function content. You don't want this, since the function call executes the function. So you want to place the function call outside/after the function, you do this by indenting it with zero spaces


#5

The above is noted.

Thank you!


#6