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

Hinh Phan
Hinh Phan
2,564 Points

My letter game doesn't run like Kenneth. Am I missing somethings?

It doesn't print out the end = ' '

import random

#make a list of words
words = [
    'blue',
    'green',
    'black',
    'bean',
    'sean',
    'yellow',
    'white',
    'purple'
    'melon'
    'lemon'
]

while True:
    start = input("Press enter/return to start, or enter Q to quit")
    if start.lower() != 'q':
        break

secret_word = random.choice(words)
bad_guesses = []
good_guesses = []

while len(bad_guesses) < 8 and len(good_guesses) != len(list(secret_word)):
    #draw space
    for letter in secret_word:
        if letter in good_guesses:
            print(letter, end ='')
        else:
            print('_', end ='')

        print('')
        print('Strikes: {}/8.'.format(len(bad_guesses)))
        print('')

        guess = input("Guess the secret words: ").lower()
        if len(guess) != 1:
            print("You can only guess 1 word")
            continue
        elif guess in bad_guesses or guess in good_guesses:
            print("You can only guess the letter one time")
            continue
        elif not guess.isalpha():
            print("You can only guess the letter in alphabet order")
            continue

        if guess in secret_word:
            good_guesses.append(guess)
            if len(good_guesses) == len(list(secret_word)):
                print("You win the game! My word was {}".format(secret_word))
                break
        else:
            bad_guesses.append(guess)
    else:
        print("You didn't get it!")
Press enter/return to start, or enter Q to quits                                                                                                                         
_                                                                                                                                                                        
Strikes: 0/8.                                                                                                                                                            

Guess the secret words: d                                                                                                                                                
_                                                                                                                                                                        
Strikes: 1/8.                                                                                                                                                            

Guess the secret words: f                                                                                                                                                
_                                                                                                                                                                        
Strikes: 2/8.               

6 Answers

your else is not in line with (with)

import random

make a list of words

words = [ 'blue', 'green', 'black', 'bean', 'sean', 'yellow', 'white', 'purple', 'melon', 'lemon', ]

while True: start = input("Press enter/return to start, or enter Q to quit") if start.lower() != 'q': break

secret_word = random.choice(words) bad_guesses = [] good_guesses = []

while len(bad_guesses) < 8 and len(good_guesses) != len(list(secret_word)): #draw space for letter in secret_word: if letter in good_guesses: print(letter, end ='') else: print('_', end ='')

    print('')
    print('Strikes: {}/8.'.format(len(bad_guesses)))
    print('')

    guess = input("Guess the secret words: ").lower()
    if len(guess) != 1:
        print("You can only guess 1 word")
        continue
    elif guess in bad_guesses or guess in good_guesses:
        print("You can only guess the letter one time")
        continue
    elif not guess.isalpha():
        print("You can only guess the letter in alphabet order")
        continue

    if guess in secret_word:
        good_guesses.append(guess)
        if len(good_guesses) == len(list(secret_word)):
            print("You win the game! My word was {}".format(secret_word))
            break
    else:
        bad_guesses.append(guess)

else: print("You didn't get it!")

man i hate when it does that but yea bottom else is not in line with top with

oops while

@Hinh Phan, you have the right code the only thing you need to do is check your list again you will notice that there is something missing on purple(,)melon(,)and lemon(,) hopefully this helps

Hinh Phan
Hinh Phan
2,564 Points

That's help. The code run. But the (end string doesn't seem work) If it is right, should be print for instance every time guessing the right letter e_ _a __n And when all the letters are guessed, the loop doesn't break.

Press enter/return to start, or enter Q to quit _ Strikes: 0/8.

Guess the secret words: guess You can only guess 1 word _ Strikes: 0/8.

Guess the secret words: yellow You can only guess 1 word _ Strikes: 0/8.

Guess the secret words: blue You can only guess 1 word _ Strikes: 0/8.

Guess the secret words: sean You can only guess 1 word _ Strikes: 0/8.

Guess the secret words: white You can only guess 1 word You didn't get it! _ Strikes: 0/8.

Guess the secret words: melon You can only guess 1 word _ Strikes: 0/8.

Guess the secret words: lemon You can only guess 1 word _ Strikes: 0/8.

Guess the secret words: purple You can only guess 1 word _ Strikes: 0/8.

Guess the secret words: white You can only guess 1 word _ Strikes: 0/8.

Guess the secret words: black You can only guess 1 word You didn't get it! _ Strikes: 0/8.

Guess the secret words: d _ Strikes: 1/8.

Guess the secret words: a _ Strikes: 2/8.

Guess the secret words: s _ Strikes: 3/8.

Guess the secret words: r _ Strikes: 4/8.

Guess the secret words: g You didn't get it! _ Strikes: 5/8.

Guess the secret words: v _ Strikes: 6/8.

Guess the secret words: w _ Strikes: 6/8.

Guess the secret words: i _ Strikes: 6/8.

Guess the secret words: m _ Strikes: 7/8.

Guess the secret words: h You didn't get it! w Strikes: 7/8.

Guess the secret words: s You can only guess the letter one time h Strikes: 7/8.

Guess the secret words: t i Strikes: 7/8.

Guess the secret words: p t Strikes: 8/8.

Guess the secret words: w You can only guess the letter one time _ Strikes: 8/8.

Guess the secret words: g You can only guess the letter one time You didn't get it!

Process finished with exit code 0

Hinh Phan
Hinh Phan
2,564 Points

Awesome help. Great to have people like you in the community. I'm very appreciated.

your welcome