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

Justo Montoya
Justo Montoya
3,799 Points

would len(good_guesses)==len(list(secret_word)), if the secret word has 2 of the same letter?

Hey guys, I've watched this video several times to see what i may have missed something but I just don't see it.

My main problem is if the secret_word has 2 of the same letter ex "sparta",

The loop would only append the letter once even though it turns the underscores into its corresponding letters. And if you were to type in the letter twice the loop responds that you have already typed in the letter.

elif guess in good_guess or guess in bad_guesses:
    print("You already guessed this letter.")

if guess in secret_word:
good_guesses.append(guess)
    if len(good_guesses)==len(list(secret_word)):
        print("correct! The secret word it {}."format(secret_word))
        break
    else:
        bad_guesses.append(guess)

if secret_word=sparta when the user guesses 'a', good_guess=[] gets "a" only once , and can't get another one so the len(good_guesses) will never equal len(list(secret_word))

Is there something else I'm missing?

1 Answer

It seems like a bug, Justo. Substituting "set" for "list" worked for me, as set enforces uniqueness.

        if len(good_guesses) == len(set(secret_word)):
Justo Montoya
Justo Montoya
3,799 Points

Thanks Patrick! I really appreciate it.