Printing out a list item by item in a function


#1

n = [3, 5, 7]

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

why should i do?
error:
Oops, try again. The body of your function should not contain any references to 'n'


#2

This is the line that defines the function. All your code should be inside the code block.

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

print_list(n)

Notice that inside the code, the list is given a name, x but when we call the function we pass in n, the name of the list we have outside of the function.


#3

sorry i dont get it explain more


#4

Study the example. There is enough information there. Be sure you take the time to read lesson text and follow up with search of terms you don't understand. You've been getting plenty of help but don't seem to grasp the answers people are telling you. Are you sure you are up to this task?


#6

look i am 14 years iam planing to be a programmer whatever happens i am ready to do it i just wonna learn and practice with code after finishing python and now i will try my best and thanks for you for help and to this site too


#7

Good for you mate ..... tech industry need people like you .... I'm happy for you ....


#8

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