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 Refinement

Michal Janek
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Michal Janek
Front End Web Development Techdegree Graduate 30,654 Points

Duplicate letters

Which part of refined game deals with duplicate letters? I got lost somewhere. I believe it is somewhere where the program evaluates whether the guessed character (guess) is IN secret word hence

if guess in secretName:
            goodGuess.append(guess)
            found = True
            for letter in secretName:
                if letter not in goodGuess:
                    found=False
            if found:
                print("You win!")
                print("The Secret Name was {}.".format(secretName))
                done = True

Michal Janek,

I do not remember, does the game place all of the duplicate letters, or does it only do one?

Thank you,

1 Answer

Umesh Ravji
Umesh Ravji
42,386 Points

Hi Michal, I'm not sure if he explicitly states in the video that the code is there to deal with words that contain duplicates of characters, but the code you have posted is in the right place.

            # Assume the user has correctly guessed the entire word.
            found = True

            # Look through all of the letters in the secret word. If a letter
            # has not been guessed yet, set found to be False.
            for letter in secret_word:
                if letter not in good_guesses:
                    found = False

Here's an example of how it works (not valid python):

secret_word = 'banana'
good_guesses = ['b', 'a', 'n']

found is set to True
for letter in secret_word loop:
    check: if 'b' not in good_guesses, condition is False, found remains True
    check: if 'a' not in good_guesses, condition is False, found remains True
    check: if 'n' not in good_guesses, condition is False, found remains True
    check: if 'a' not in good_guesses, condition is False, found remains True
    check: if 'n' not in good_guesses, condition is False, found remains True
    check: if 'a' not in good_guesses, condition is False, found remains True

found is still True