Python Python Basics (2015) Letter Game App Letter Game Refinement

Problems to understand how the functions def draw and def get_guesses get the parameters passed to them

Hello Everyone!

I am having a hard time trying to understand where the parameters for def draw(bad_guesses, good_guesses, secret_word): clear() and def get_guess(bad_guesses, good_guesses): are coming from in the letters game.

As far as I understood if a function has 3 parameters, all 3 of them must be passed in order to have it working, however, in the game, the "draw" function works even though we are guessing 1 letter at time (which means only 1 parameter is being passed right?).

Could anyone please clarify this to me? It is driving me crazy!


Edit: Are we passing the variables themselves as parameters? Is that way he uses def get_guess(bad_guesses, good_guesses)"?

Because on the earlier videos, we had: def lumberjack(name, pronoun):

and then we called it using lumberjack("name", "he's")

Does this means that when creating a function with parameters i can use a variable that already exists? Like this:

example1 = hi
example2 = hey

def new_func(example1, example2):
    print("{} mon, {} dad".format(example1, example2)


Hello Gabriel! Great question.

A list, whether empty or full, always has a value and is an object. As we move through the guesses, we are adding a letter value to either good_guesses or the bad_guesses list. However, because the value of an empty list still has a value (weird I know!), the function can successfully be executed. You can test this by using the following code:

good_guess = []
bad_guess = []

def draw(good_guess, bad_guess):
   print("{} {}".format(good_guess, bad_guess))

draw(good_guess, bad_guess)
# when we run the program, our results will be
# >>> [] [] 

Hi Fergus, thanks a lot for your response!

One more question though:

when we created the function

def get_guess(bad_guesses, good_guesses):

the arguments have the name of the variables, I tried to modify this to

def get_guess(arg1,arg2):

but i get an error. My understanding is: you can name your arguments whatever, because what is important is passing the value we want when calling the function. I really can't get why changing the name of the args here breaks it. Wouldn't the code below work correctly?:

def get_guess(arg1,arg2):
   print("1 {}, 2 {}".format(arg1,arg2))

get_guess(bad_guesses, good_guesses)

Once again i really appreciate the help!

1 Answer

AJ Salmon
AJ Salmon
5,675 Points

Hey Gabriel!

To answer your second question: yes. The reason he uses the actual variable names in the parameter is simply for clarity, and your code would work perfectly. If you don't use the actual variable names in the parameter, I'd suggest making a note documenting your thought process so that you remember exactly what to pass to the argument when you call it later on. Hopefully this clears it up! Happy coding :)


Hello AJ!

Thanks a lot for the answer, now it is clear to me what happens!

AJ Salmon
AJ Salmon
5,675 Points

My pleasure! I'm glad you're comfortable with the concept.