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

I don't really understand why done is in the argument in play()

So on line 79 it says done = True when you find the word

theres a function on line 60 called

def play(done):
    secret_word = random.choice(words)
    bad_guesses = []
    good_guesses = []

What I dont understand is when we've found the word wouldn't we want done to be False (although if you think of it in "English" it may not sound right,,, but in code it makes sense because if done is true then play would run again and you'd clear, right?

Jakob Hansen
Jakob Hansen
13,746 Points

If we would set it to False when we found the word, the game wouldn't reset properly

        if guess in secretWord:
            found = True
            for letter in secretWord:
                if letter not in goodGuesses:
                    found = False

This first checks if our guessed letter is inside the secretWord, and then sets the found variable to True, it then iterates over each letter inside the secret word, and checks if each of those letters are NOT inside goodGuesses, if they are not all inside goodGuesses, it means we haven't found the full word yet, and we set the found to False again,

            if found:
                print("You win!")
                print("The secret word was {}".format(secretWord))
                done = True

It then checks if found is True If it is True, then that means we didn't enter the nested for loop above, and we have the all the letters in the word. and here we set done = True

done is just a variable to track whether or not we have already won the game or not. in case of the else statement below we also set done = True, but that's because the user is out strikes, and has lost the game.

we then come to this:

        if done:
            playAgain = input("Play again? Y/N").lower()
            if playAgain != 'n':
                return play(done=False)

We check to see if done is True, if it is, jump inside the condition and we basically just ask if the user wants to play again. in case he says doesn't say 'n' (no), we set done to False, so on the next iteration, of the while loop, we start over, from the start.