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

Hussein Amr
Hussein Amr
2,461 Points

done()

I don't understand how the done argument works can someone please explain? Thank you

1 Answer

Hi, Hussein Is the code below what you're talking about? [I don't see any code or a specific reference to the video (i.e. "6 min into the video")]

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

done as it relates to this bit of code "done" is a variable that is set to True or False based on the code before it (which is not shown here... see next bold section for a overall general explanation). If done is True, then the user is asked if they want to play again via the input() function. Then another if statement is used to either run the game again (by the play function calling itself via "return play(done=False)"... effectively exiting out of the current play() and returning a new play()) if the user does not type 'n'... otherwise, the program exits.

done as it relates elsewhere in the play() function: the play function uses the "done" variable to keep up with where the user is in the game, in a sense. For example, has the user won? Then the current game is done. Has the user lost (too many bad guesses)? Then the current game is done also. Based on the value in the done variable (and other things), the program knows when to tell the user they won or lost and when to ask if they would like to play again.

This isn't the easiest example to understand if you're new to Python (I know it wasn't for me!), so don't worry if it's all still a bit fuzzy : )
Hope that helps, D.

Hussein Amr
Hussein Amr
2,461 Points

Thank you! kinda got it hehe