12/12 NOT Printing out a list item by item in a function


#1



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

Print 3, 5, 7

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


#2

this line:

for x in range(0,len(x))

now the variable which should the individual items of the list, has the same name as the list? This sounds like a bad idea, name it anything else:

for y in range(0,len(x)):

then y contains the indexes (due to range) so then you can use y as index to access the items in the list (x)


#3

I did have it a different letter. I get this back
[3,5,7]
none
on the output screen. and the error message: Oops, try again. It looks like you either didn't call print_list(n) or there is something wrong because 3 wasn't printed. This is my current code.

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

print print_list(n)


#4

you should use print, not return


#5

I changed return x to print x and now I get the following output:
[3, 5, 7]
[3, 5, 7]
[3, 5, 7]
None
None

Also this error message.
Oops, try again. It looks like you either didn't call print_list(n) or there is something wrong because 3 wasn't printed. I am also getting confused. Does it want to print the 3, 5, 7 out of the brackets? and if so I am not sure why it is in them.


#6

okay, so what does x contain? As you might have guessed, it contains the list. what does y contain? indexes, this indexes can be used to access elements in the lists.


#7

Thank you that worked.


#8