Bummer! You have been redirected as the page you requested could not be found.

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

Main Loop of this Code Example

Hi there. In the end of his code, Kenneth puts the following lines of code in his project:

def welcome():
    start = input("Press enter/return to start or q to quit ").lower()
    if start == 'q':
        sys.exit()

done = False

while True:
    clear()
    welcome()
    play(done)

What I'm unclear about is why he does this, since that while True loop will never be implemented. The repeating code is in the play loop which calls on itself if it should run again. To implement the same functionality, I did:

clear()
print("\nWelcome to the Letter Game\n")
choice = input("Begin game (Y/n): ").lower()
if choice != 'n':
    play(False)

Is the while True loop that calls play(done) a fail proof if we were to change the play method? Thanks!

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,468 Points

I agree that the while loop will not run twice because play either runs itself again or hard exits. Given this, it isn't clear why the while loop was necessary. Your code suffices to get the job done. My speculation is in developing the play function, until the if done section was completed, the while loop would have run if instead of a sys.exit(), a simple return was used. Good question!