Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialryan smith
687 PointsI 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):
clear()
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
13,746 PointsJakob Hansen
13,746 PointsIf we would set it to False when we found the word, the game wouldn't reset properly
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,
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:
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.