for letter in blanks: # Show the secret word with spaces in between each letter print(letter, end=' ') 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: print('Guess a letter.') guess = input() guess = guess.lower() if len(guess) != 1: print('Please enter a single letter.')

#check if the player has won foundallletters = True for i in range(len(secretword)): if secretword[i] not in correctletters: foundallletters = False break if foundallletters: print('Yes! the secret word is "' + secretword + '"! You have won!') gameisdone = True else: missedletters = missedletters + guess

#check if the player has guessed too many times and lost if len(missedletters) == len(hangmanpics) - 1: displayboard(hangmanpics, missedletters, correctletters, secretword) print('You have run out of guesses!\nAfter ' + str(len(missedletters)) + ' missed guesses and ' + str(len(correctletters)) + ' correct guesses.') gameisdone = True

#ask the player if they want to play again if gameisdone: if playagain(): missedletters = '' correctletters = '' gameisdone = False secretword = getrandomword(words) else: break