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

A quick question in this part

if i do this with a choose word apple. when i input p this counts it only one time. So even I input all of these 4 words(a p l e).

My results still be 4/5, is this a bug of my code?

Here is my code.

import random

words=['apple', 'banana', 'orange', 'melon', 'lemon', 'pear', 'berry', 'tree', 'dish', ]

while True:

start=input("enter or q ")
if start.lower()=='q':
    print('bye bye')
    break
answer = random.choice(words)
good_guess =[]
bad_guess =[]
while len(bad_guess)< 20  and len(good_guess)!=len(answer):
    for letter in answer :
        if letter in good_guess:
            print (letter,end=" ")  
        else : 
            print('_',end = " ")
    print("  ")
    print("strike {}/{}".format(len(good_guess),len(answer)))
    print("  ")
    guess=input("please input your letter:").lower()
    if len(guess)!=1:
        print("sorry you can only input a letter")
        continue
    elif guess in bad_guess or guess in good_guess:
        print ("you already idi it")
        continue
    elif not guess.isalpha():
        print("alpha only")
        continue
    if guess in answer:
        good_guess.append(guess)
    if len(good_guess)==len(answer):
        print ("you win the guess")
        print(answer)
        break
    else:
        bad_guess.append(guess)           
else:
    print("you faild")
Cheo R
Cheo R
37,150 Points

Post your code so we can look at it.

1 Answer

Steven Parker
Steven Parker
231,271 Points

You'll need a different strategy for determining a win.

When a word has one or more repeating letters, the number of guesses it takes to win will be less than the word size. Simply comparing the word size to the number of guesses won't work for those words.

So you'll either need to determine the number of unique letters the word has, or you could check if every letter in the word has been guessed.