12. Printing out a list item by item function. (Lesson Complete)



I would like to be sure that this is what the lesson intended for me to do. The code works and allows me to continue but it felt too easy.

I feel like the lesson intended for me to use the provided code's return values in some way...not to remove it completely.

n = [3, 5, 7]

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


That function isn't correct, your function ignores the value given to it as an argument.
It's also using n, which is not something that the function should be mentioning at all. It should only be concerned with the value given to it.


@ionatan Can you go more in depth as to how he's ignoring the value? I have just about the same code, except I didn't use n unless required to, however, I'm still getting the error message. Can you help me understand my mistake?

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


This worked for me on this lesson. What does the error message say and what is the rest of your code?

He was ignoring the value of 'x' (the argument) by using 'n' which is outside of the function but works, because it is defined before the function is called.


Delete the above for loop the system already made. When I did that for some reason it works.


This is what I did but I didnt understand if this is what the lesson intended. I dont want to move on in the course not learning what the lesson intended for me to learn.


Right. It was telling me not to use n until I removed their function. I'm more worried that I am doing something that works but not learning what the lesson intended to teach.


I'm fairly certain that the lesson here is that you can do the same thing in a function as you can outside of it. Meaning that you don't have to go outside of the function if you can do it inside. Putting inside the functions makes it clearer to anyone that reads the code what the intent of the loop/list is and make it more organized which is always a good practice. The next lessons after this one will really show how else a function can be more beneficial to loops/lists than if you were to leave them outside.


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