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

Mark Southcombe
Mark Southcombe
3,361 Points

The code does not work if there are repeating letters in the word you are guessing.

If the word has repeating letters then the good_guesses will not equal the length of the list of secret_word so it will not break.

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,426 Points

Good observation! Secret words with repeating letters will not match lengths. This is a know issue.

In the Video Teacher's Notes, Kenneth says:

    "Did you notice?

    There's a tricky condition (on purpose) in the final version of our code from this video. Words that have repeated characters won't be marked as correct once they're all correctly guessed due to our len() comparisons. See if you can find a way to fix that yourself!"

The solution would be to make a set out of it, to compare unique letters only:

len(good_guesses) == len(set(secret_word))

>>> a = "blueberry"
>>> len(a)
9
>>> len(set(a))
6
Joey B
Joey B
5,275 Points

Is there any advantage to comparing the lengths to the set itself? As in,

set(good_guesses) == set(secret_word)

It seems to be working for me.

Peter Trefren
Peter Trefren
13,898 Points

print out win/lose

    if guess in secret_word:
        good_guesses.append(guess)
        done = True
        for secret_letter in secret_word:
            if secret_letter not in good_guesses:
                done = False
        if done:
            print("You win! The word was {}".format(secret_word))
            break
    else:
        bad_guesses.append(guess)