Python
Python
```
import random
HANGMAN_PICS = ['''
+---+
| |
=========''', '''
+---+
| |
O |
=========''', '''
+---+
| |
O |
| |
=========''', '''
+---+
| |
O |
/| |
=========''', '''
+---+
| |
O |
/|\ |
=========''', '''
+---+
| |
O |
/|\ |
/ |
=========''', '''
+---+
| |
O |
/|\ |
/\ |
|
=========''']
WORDS = 'ant baboon badger bat bear beaver camel cat clam cobra cougar
coyote crow deer dog donkey duck eagle ferret fox frog goat goose hawk lion
lizard llama mole monkey moose mouse mule newt otter owl panda parrot
pigeon python rabbit ram rat raven rhino salmon seal shark sheep skunk
sloth snake spider stork swan tiger toad trout turkey turtle weasel whale wolf
wombat zebra'.split()
def getRandomWord(wordList):
# This function returns a random string from the passed list of strings.
return wordList[wordIndex]
print(HANGMAN_PICS[len(missedLetters)])
print()
print()
if secretWord[i] in correctLetters:
blanks = blanks[:i] + secretWord[i] + blanks[i+1:]
for letter in blanks: # show the secret word with spaces in between each
letter
print()
def getGuess(alreadyGuessed):
# Returns the letter the player entered. This function makes sure the
player entered a single letter, and not something else.
while True:
if len(guess) != 1:
else:
return guess
def playAgain():
# This function returns True if the player wants to play again, otherwise it
returns False.
return input().lower().startswith('y')
print('H A N G M A N')
missedLetters = ''
correctLetters = ''
secretWord = getRandomWord(WORDS)
gameIsDone = False
while True:
if guess in secretWord:
foundAllLetters = True
for i in range(len(secretWord)):
foundAllLetters = False
break
if foundAllLetters:
print('Yes! The secret word is "' + secretWord + '"! You have won!')
gameIsDone = True
else:
gameIsDone = True
# Ask the player if they want to play again (but only if the game is done).
if gameIsDone:
if playAgain():
missedLetters = ''
correctLetters = ''
gameIsDone = False
secretWord = getRandomWord(WORDS)
else:
break
```
Output:
```
HANGMAN
+---+
| |
|
|
=========
Missed letters:
____
```