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


#1



https://www.codecademy.com/en/courses/python-beginner-nzzVa/3/1?curriculum_id=4f89dab3d788890003000096


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]
print_list(n)


#2

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.


#3

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)

#4

Thanks! this worked great


#5

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)


#6

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