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 trialAshley Keeling
11,476 Pointswhat is 'done'?
in the video he uses done as a argument for the play function , I don't get where it has come from. thanks
1 Answer
Chris Freeman
Treehouse Moderator 68,454 Pointsdone
is used as a parameter for the play
function to determine if play should begin. Initially, done
should be False
otherwise you would only get one guess before the if done:
statement is reached and the code asks to play again.
The initial value of done
needs to be passed into the play
function using:
play(False)
# or
play(done=False)
Mathew V L
2,910 PointsMathew V L
2,910 PointsHi Chris,
So done = True means you lost in this exercise and done =False would be vice versa?
Is this because he set done = False at the bottom? if done = True, what happens? Definitely hard to follow, For a while, I've been trying to get a good understanding of what Kenneth Love was trying to write for this 1 video alone -.-
Chris Freeman
Treehouse Moderator 68,454 PointsChris Freeman
Treehouse Moderator 68,454 PointsWhen I am trying to understand what a variable is used for, I break the process into two parts.
Under what conditions is the variable set
At the bottom of the code, the variable
done
is set toFalse
as the game starts. In the game,done
is set toTrue
when the play ends due the all secret letters guessed or too many bad guesses made.How is the variable used in other statements
The variable
done
is used to control whether or not to ask if the game should continue. Ifdone
isTrue
, ask the questions, otherwise skip it and continue the game.So now knowing why the variable
done
gets set and what it controls its purpose might be clearer.This is also an example of how a variable name might make the code more understandable. Perhaps the code would be clearer if, instead of
done
, the variable was named "ask_to_start_new_game".