Printing out a list item by item in a function


#1

Hi,

I really need help with this exercise. The instructions are:

  1. Define a function called print_list that has one argument called x.
  2. Inside that function, print out each element one by one. Use the existing code as a scaffold.
  3. Then call your function with the argument n.

The hint: You can simply place the code on lines 3 - 4 inside a function definition. Make sure to indent properly! And you'll have to change the n to x

My code:

x= [3, 5, 7]

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

I get the error: File "python", line 4
for i in range(0, len(n)):
^
IndentationError: expected an indented block

What should I do? I've looked at the codes that other people have uploaded here and they don't work for me as well.


#2

Another attempt: x = [3, 5, 7]

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


#3

Did you type it like this?

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

If it's still giving trouble, re-type the code and make sure you indent without any extra space at the beginning of the lines.


#5