Printing out a list item by item in a function


n = [3, 5, 7]

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

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


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]


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.


sorry i dont get it explain more


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?


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


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


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