Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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')
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")
    elif guess in bad_guess or guess in good_guess:
        print ("you already idi it")
    elif not guess.isalpha():
        print("alpha only")
    if guess in answer:
    if len(good_guess)==len(answer):
        print ("you win the guess")
    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
215,954 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.