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

Hi guys, I stuck on this python letter game, the 'count' I set is for counting the distinct guess in secret_word.

import random
words=[
    'apple',
    'orange',
    'peach',
    'lemon',
    'kiwi',
    'pineapple',
    'strawberry',
    'blueberry']
count=0
while True:
    start= input("Please enter/return to start, or enter Q to quit: " )
    if start.lower()=='q':
        break
    secret_word= random.choice(words)
    good_guess=[]
    bad_guess=[]    

    while len(bad_guess)<5 and count!=len(list(secret_word)):
        for letter in secret_word:
            if letter in good_guess:
                print(letter,end='')
                count=count+1
            else:
                print('_',end='')  

        if count==len(list(secret_word)):
            print('')
            print("You win the word is {}".format(secret_word))
            break 


        print('')        
        print('Strike: {}/3'.format(len(bad_guess))) 
        print('')

        guess=input("Guess a letter: ").lower()
        if len(guess)!=1:
            print("You can only enter 1 letter")
            continue    
        elif guess in good_guess or guess in bad_guess:
            print("You already guess this letter")
            continue
        elif not guess.isalpha():
            print("This is not a letter")
            continue    

        if guess in secret_word:
            good_guess.append(guess) 
        else:
            bad_guess.append(guess)
    else:
        print("Sorry, you lose")