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



Oops, try again. The body of your function should not contain any references to 'n'

It should work, however the checker look for the body with the n variable, hence even if those are text the error message still exists

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]


I got the same problem. This is definitely a bug. Commenting out the for loop at the beginning does nothing either. The hint even explicitly says you can just copy the for loop and replace the n's with x's.


This is the code that I used, it essentially is the same as the person above me posted except that at the end I added the "print print_list(n)" which I imagine since I had defined print_list already it just took list n = [3,5,7] and just ran it through the defined print_list(x) code... make senes? I am new to this and its the best way I can explain it.

n = [3, 5, 7]

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

print print_list(n)


Thanks! this worked great


As per the function, once you activate the function it will automatically print out the list. There is no need of the extra print in front. However, I do not understand the presence of the extra print in front of the print_list(n)


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