Oops, try again. print_list should take exactly one argument (a list to print)


#1

Oops, try again. print_list should take exactly one argument (a list to print).

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

Why isn't this working?
Can anyone help me?


#3

I indented everything correctly too.
I don't understand.


#4

Well you have two for loops in your problem.

def print_list(a_list_here):
    """
    This function prints a flattened list.
    """
    print(*a_list_here)

While this is cheating it does work, now let's create a function that uses no builtin functionality.

def print_list(a_list_here):
    """
    This function prints a flattened list.
    """
    hold = ""
    for item in a_list_here:
        hold = hold + str(item) + ' '
    print(hold)

If you want it to print line after line just change the for loop according and remove the hold variable.

If you have any questions ask away.

EDIT:

Also just pass the list to the function

n = [3, 5, 7]
print_list(n)
# OUTPUT: 3 5 7