I am studying the solution code for Step 3 and it makes no sense to me. I also copied and pasted the solution code for Step 3 into my code box and received a NameError warning. These are all the codes that I have so far …
I don’t understand why I was instructed to call the function add_gamer with gamers as the second argument. Why gamers? gamers is supposed to be the holding list for all the people who will attend the game night. I was instructed to created an empty list called gamers as the very first line of code. Also, it’s this very same second argument of gamers that I receive the following message …
Hi janbazant. Thank you for being here! I’m going cross-eyed trying to figure out why I still keep getting that NameError for a not defined “gamers.” Please see screenshot below … Please note that my screenshot cut off my first line of code which is gamers =
Thank you janbazant! I literally spent half this morning and an hour just now running and rerunning the code over and over again. I followed your directions and went to each cell and ran each one again. It cleared! No NameError! What happened? Anyway, I am glad it worked. Very relieved.
Now that the second argument gamers is not giving me an Error, can you help me understand why it’s the second argument? Why is the first code that I wrote at the top of the page the second argument here in the add_gamer function?
It’s the second argument because the list was the second parameter for the function (in the definition of add_gamer earlier). def add_gamer(gamer, gamers_list):
Outside of that function definition, the variable was gamers
(and gamers = [] is earlier in the code)
It does not matter what you call the parameter inside the function definition;
as long as the same thing is used everywhere inside the function definition.
I think gamers_list was used just to emphasize that it could be something different from gamers
You said games = … sorry I’m not seeing where this is. Did you mean gamers = which is at the top of the code?
This recycling and mixing of gamers and gamers_list throughout the Code Solution is very confusing to me.
I’ve moved on to Step 6 and here again the Code Solution uses the term gamers_list instead of gamers and I am confused! The instructions actually say that the function should iterate through each gamer in gamers_list … the instructions didn’t say to iterate in ‘gamers.’ But I thought that ‘gamers’ is the master list and ‘gamers_list’ is not … because ‘gamers_list’ is just a second argument for a function?!
gamers was the variable that’s used as an argument for a function call for the function add_gamer gamers_list is a parameter for the add_gamer function, used in the function definition.
In this case, they represent the same values. gamers is the second argument for the function call,
therefore it is used for the gamers_list parameter (the second parameter of the function definition)
Thank you so much for your time and your thoughtful explanations. I think I have hit a roadblock in my brain and will try again tomorrow. I really appreciate your help!
Me again. Back at it. New day. Fresh perspective. So, the ‘gamers’ which is the second parameter in the add_gamer function is the exact same as the ‘gamers’ list which we wrote as the first code in this project. Correct?
In this case, gamers is the second argument when add_gamer is called, so whatever is in gamers is used for the gamers_list parameter of the add_gamer function.
Just ran into this problem myself. Jupyter Notebooks wanted to run the empty list first. The ‘name error’ was due to the list not being added to the running code block until tested. Thanks a bunch! This was going to bug the crap outta me!