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


#1

Continuing the discussion from 12. Printing out a list item by item in a function:

Here is my code but it is not working and giving the error "The body of your function should not contain any references to 'n'"

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_list(n)

#2

Hi, try to remove the for in range... .


#3

Hi,

just use for number in n: number will automatically take on every value in n.

You also can do things like

for character in "This is a string":
    print character

to print out all characters in a string.