Implement a python version of the game Hangman in which a player attempts to guess a secret word one letter at a time. Normally Hangman is a two-player game but in your version the user will play three rounds against the computer. Use the following as the secret word in each round: 1. “APPLE” 2. “OBVIOUS” 3. “XYLOPHONE” Here are the steps to follow in each round: Print the secret word with each letter replaced with the underscore character, “_” Prompt the user to enter a letter or word using the following message, “Enter a letter or word: ”. If the user enters a single letter, check if that letter is in the secret word (case-insensitive). The user can make up to 6 letter guesses in a round. If the user guesses a letter they have already guessed, print the message “You've already guessed that letter!” and don’t count it as one of their 6 guesses. Go straight to step 6. If the user enters a word, check if the word matches the secret word (case-insensitive). Word guesses should not count toward the user’s total number of guesses. After the user has made their guess, check if the game is over. The game is over if the user has guessed 6 letters but not revealed the word (they lose) or, if the user correctly guesses the word. If the game is NOT over: Print the secret word with all letters except any the user has correctly guessed replaced by underscores. Print “Your guesses so far: “ followed by each letter the user has guessed so far. Return to step 2. If the game is over, print the result. If the player won, print “You win!” If the player lost, print “You lose! The word was “ followed by the secret word Move on to the next round, if applicable. When the user has played all three rounds, print “You won out of 3”, where is the number of rounds the player won.
Implement a python version of the game Hangman in which a player attempts to guess a secret word one letter at a time. Normally Hangman is a two-player game but in your version the user will play three rounds against the computer. Use the following as the secret word in each round:
1. “APPLE”
2. “OBVIOUS”
3. “XYLOPHONE”
Here are the steps to follow in each round:
-
Print the secret word with each letter replaced with the underscore character, “_”
-
Prompt the user to enter a letter or word using the following message, “Enter a
letter or word: ”.
-
If the user enters a single letter, check if that letter is in the secret word (case-insensitive). The user can make up to 6 letter guesses in a round. If the user guesses a letter they have already guessed, print the message “You've already guessed that letter!” and don’t count it as one of their 6 guesses. Go straight to step 6.
-
If the user enters a word, check if the word matches the secret word (case-insensitive). Word guesses should not count toward the user’s total number of guesses.
-
After the user has made their guess, check if the game is over. The game is over if the user has guessed 6 letters but not revealed the word (they lose) or, if the user correctly guesses the word.
-
If the game is NOT over:
-
Print the secret word with all letters except any the user has correctly guessed replaced by underscores.
-
Print “Your guesses so far: “ followed by each letter the user has
guessed so far.
-
Return to step 2.
-
-
If the game is over, print the result.
-
If the player won, print “You win!”
-
If the player lost, print “You lose! The word was “ followed by the secret word
-
Move on to the next round, if applicable.
-
When the user has played all three rounds, print “You won <X> out of 3”, where <X> is the number of rounds the player won.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 5 images