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


#1

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

I have no clue what's wrong

can someone explain this in a very simple way please and thank you!

n = [3, 5, 7]

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

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


print add_function(m, n)

someone please tell what im doing wrong and how to fix it


#2

So in your "def print_list(x): " function it says "print_list(n)"
and then outside of the function it says “print_list(n)” again.

You only need the one outside of the function because the one inside will keep on
repeating itself inside of the for loop. You also don’t need any of this:

“for i in range(0, len(n)):
print n[i]
print add_function(m, n)”

This is what I did and it worked for me:

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

Hope this is helpful! :smile:


#3

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