Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the code in PYTHON 3. Extra Credit: Game - hangman [20 points] Write a han

ID: 3866332 • Letter: W

Question

Write the code in PYTHON 3.

Extra Credit: Game - hangman [20 points] Write a hangman game that randomly generates a word and prompts the user to guess one letter at a time, as shown in the sample run. Each letter in the word is displayed as an asterisk. When the user makes a correct guess, the actual letter is then displayed. When the user finishes a word, display the number of osentinuethegamapreseETER misses and ask the user whether to continue playing. Create a list to store the words, as follows: The word is: receive # Use any words you wish words = [ "write" , "that" , "program" , ] Name the source code files "hangman.py" Sample run: (Guess) Enter a letter in word pr**r* >e (Guess) Enter a letter in word pr..r.. > (Guess) Enter a letter in word pror*> g (Guess) Enter a letter in word progr** > n p is already in the word n is not in the word

Explanation / Answer

#importing the time module import time #welcoming the user name = raw_input("What is your name? ") print "Hello, " + name, "Time to play hangman!" print " " #wait for 1 second time.sleep(1) print "Start guessing..." time.sleep(0.5) #here we set the secret word = "secret" #creates an variable with an empty value guesses = '' #determine the number of turns turns = 10 # Create a while loop #check if the turns are more than zero while turns > 0: # make a counter that starts with zero failed = 0 # for every character in secret_word for char in word: # see if the character is in the players guess if char in guesses: # print then out the character print char, else: # if not found, print a dash print "_", # and increase the failed counter with one failed += 1 # if failed is equal to zero # print You Won if failed == 0: print " You won" # exit the script break print # ask the user go guess a character guess = raw_input("guess a character:") # set the players guess to guesses guesses += guess # if the guess is not found in the secret word if guess not in word: # turns counter decreases with 1 (now 9) turns -= 1 # print wrong print "Wrong " # how many turns are left print "You have", + turns, 'more guesses' # if the turns are equal to zero if turns == 0: # print "You Loose" print "You Loose "