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

Joel Price
Joel Price
13,711 Points

Upon start and when entering a guess my game generates 10 'Strike: 0/7 messages before allowing me to guess again.

Somewhere along the lines my code decides that after I hit enter/guess it needs to print

_ Strikes: 0/7

_ Strikes: 0/7

_ Strikes: 0/7

Over and over again. 10 times, actually, before I can guess again.

import random


# make a list of words
words = [
    'apple',
    'banana',
    'coconut',
    'lime',
    'melon',
    'strawberry',
    'grapefruit'
]

while True:
    start = input("Press enter/return to start, or enter Q to quit")
    if start.lower() == 'q':
        break

    # pick a random word
    secret_word = random.choice(words)
    bad_guesses = []
    good_guesses = []

    while len(bad_guesses) < 7 and len(good_guesses) != len(list(secret_word)):
        # draw space
        for letter in secret_word:
            if letter in good_guesses:
                print(letter, end='')
            else:
                print('_', end='')

            print('')
            print('Strikes: {}/7'.format(len(bad_guesses)))
            print('')

        # take guess

        guess = input("Guess! ").lower()

        if len(guess) != 1:
            print("That's more than one letter! Try 'gain!")
            continue
        elif guess in bad_guesses or guess in good_guesses:
            print("You already dun that one d@wg!!")
            continue
        elif not guess.isalpha():
            print("When did numbers become letters?")
            continue

        if guess in secret_word:
            good_guess.append(guess)
            if len(good_guesses) == len(list(secret_word)):
                print("'Dun guud. The word was {}".format(secret_word))
                break
        else:
            bad_guesses.append(guess)



    else: print("SAD! Secret word was {}".format(secret_word))
    # draw guessed letters and strikes
    # print out win/lose

1 Answer

Lukas Coffey
Lukas Coffey
20,382 Points

Your print() function is inside of your for: loop. This means that for every letter in the secret_word, you print whatever is in that print function, even if nothing is there. So say there's 7 letters in the word, every time the loop hits a word, Strikes: 0/7 is printed. Try taking out one indentation out from behind your print() functions and see if that helps!