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 trial

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

fahad lashari
fahad lashari
7,693 Points

Can some please explain to me how the 'done' variable is working..confused [solved] read below for answer

How does done=true quit the programme? vice versa how does done=false run the programme. Really confused on this part as it was not explain properly in the video.

The thing that confuses me is that towards the end of the code kenneth writes:

if done:
    play_again = input("Play again? Y/n").lower()
    if play_again != 'n':
           return play(done=False)
    else:
           sys.exit()

shouldn't the statement:

if play_again !='n':

return

play(done)

so that done = True and the user can play the game again? this is the part that confuses me because if done=False when the player presses Y then shouldn't the programme just quit? The case seem to be the other way around.

Please if someone could explain this part. i'd really appreciate it

kind regards

2 Answers

fahad lashari
fahad lashari
7,693 Points

So after thoroughly looking through Kennet's game I found:

done = False

under the statement:

print('Welcome to number guess')

This basically makes the 'done' variables' value False as standard. So when Kennet writes just:

play(done)

it's actually short for:

play(done=False)

As the standard value of 'done' is False. Therefore the programme is set to run with 'done' being False. Hence why in the programme when you see:

done=True

to end the loop. It basically makes the value of 'done' into True. Therefore the programme stop running or doesn't run as the programme only runs when the value of 'done' is False.

Hope I made it clear enough for anyone that was confused.

Kind regards,

random student

# if these conditions here are met then...
done = True
# done = True is connected to
if done:  # if done is short for if done == True
  play_again # if done is True the game is run again 
# or if done is not True
  quit the game
fahad lashari
fahad lashari
7,693 Points

The thing is, the programme run with done=False. That's the reason I am confused

Fahad, you did a great job sorting all that out.