Topic: Hangman Game Help

Hello!  I started teaching myself python a couple days ago and am trying to create a Hangman game.  I have this code thus far...(images of code and error are attached for ease of viewing).
--------------------------------------------------------------------------

#Create user-defined answer (input as string)
answer=raw_input("Enter the answer: ")

#Convert string into a mutable list
answerList=[]
for letter in answer:
    answerList.append(letter)

#Create empty 'progress' list with appropriate amount of spaces
progress=[]
for letter in answer:
    progress.append('_')

#Create counter
numBlanks=1

while numBlanks>0:
    numBlanks=0
    #Get user-definded guess and store them in a list
    guesses=[]
    guesses.append(raw_input('\nEnter a guess: '))

    #Check to see if the guess is in the answer
    #If so, replace blank with guess
    for letter in answerList:
        if letter in guesses:
              progress[answerList.index(letter)]=letter

    #Print progress
    print 'Progress: '
    for letter in progress:
        print letter,

    #Update counter
    for letter in progress:
        if letter=='_':
            numBlanks+=1

print '\nCongratulations!  You guessed the answer!'
------------------------------------------------------------------------

Unfortunately, when a guess is made, only the first occurrence of the letter is replaced in the 'progress' list.
Any help is greatly appreciated!

Last edited by rbirky1 (December 28, 2011 04:09)

Post's attachments

codeAndError.png 28.93 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

Thumbs up