# Hangman Game to demonstrate user input verification, # List and String processing # # Author: Dan Fleck # Draw the hangman using text def drawHangman(misses): print "drawHangman" # Print out the word, include the blanks for any # letters not guessed already def printWord(lettersGuessed, wordToGuess): print "In printword" # Ask for a letter from the user and return it def getLetterFromUser(): letter = raw_input("Enter a letter or 1 to quit ->") # I could error check here, how? return letter # Check if a letter has already been guessed def isLetterUsed(letter, lettersGuessed): for index in range(len(lettersGuessed)): print index print lettersGuessed[index] if letter == lettersGuessed[index]: return True return False z = isLetterUsed('a', ['b','q','n','a']) print z # Check if the letter is part of the word or not # return True if it is part of the word, False otherwise def letterIsPresent(): return True # Check if all the letters have been guessed, return True if they have # False otherwise def checkForSolved(): return False # Main menu def main(): # Define the state of the game... what do we need to know? misses = 0 # How many bad guesses have they had? lettersGuessed = [] # Empty list of the letters already guessed wordToGuess = "python" # Should ask the user for this solved = False # Have we solved the whole word yet? while (not solved): # Draw the hangman drawHangman(misses) # What are my parameters? # Print out the word (with blanks) printWord(lettersGuessed, wordToGuess) # What should the parameters be? # Ask for a letter letter = getLetterFromUser() # Check if the letter is used used = isLetterUsed(letter, lettersGuessed) # What should the parameters be? # If used, print error and start over if used: continue # What does this do? # Add letter to guessed letters ### HOW? # Decide if the letter is a hit or miss if letterIsPresent(): # Parameters??? # Otherwise, check if we have solved the hangman solved = checkForSolved() # Parameters? else: # If we have a miss, update the misses # check if we have lost the game None ## I want to exit the loop when the user enters "1".. How? main()