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 Introduction

Letter Game doesn't print the "You didn't guess it" string if I run out of guesses.

I moved the print("You didn't guess it!") line under the else statement containing the bad_guesses.append(guess). I used the check if len(bad_guesses) == 7 first to ensure that the max number of strikes had been reached. I got it to work this way but in the video the else statement is put in-line with the while loop. Kenneth's method didn't work for me for some reason.

Rich Zimmerman
Rich Zimmerman
24,063 Points

can you provide a code snippit so we can see where the problem might be?

1 Answer

Hi, Christopher I think you're talking about the play function (which is a portion of the entire code in the letter game.). Below is the play function that I have when I took the course. It worked as intended for me... if you typed out the same thing as below, I would first check your indents and then check your control flow (ex. if-else statement construction). Hope this helps! D.

def play(done):
    clear()
    secret_word = random.choice(words)
    bad_guesses = []
    good_guesses = []

    while True:
        draw(bad_guesses, good_guesses, secret_word)
        guess = get_guess(bad_guesses, good_guesses)

        if guess in secret_word:
            good_guesses.append(guess)
            found = True
            for letter in secret_word:
                if letter not in good_guesses:
                    found = False
            if found:
                print('You win!')
                print('The secret word was {}'.format(secret_word))
                done = True
        else:
            bad_guesses.append(guess)
            if len(bad_guesses) == 7:
                draw(bad_guesses, good_guesses, secret_word)
                print('You lost!')
                print('The secret word was {}'.format(secret_word))
                done = True
        if done:
            play_again = input('Play again? [y]/n ').lower()
            if play_again != 'n':
                return play(done=False)
            else:
                sys.exit()