Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Program Specifications: For this you are to design and implement the standard word-game Hangman. You are probably familiar with the game Hangman , but standard
Program Specifications: For this you are to design and implement the standard word-game Hangman. You are probably familiar with the game Hangman, but standard rules are as follows:
- One player (the computer) chooses a secret word, then writes out a number of dashes (-, or _ underscore and space) equal to the word length.
- The other player (the human) begins guessing letters. Whenever they guess a letter contained in the hidden word, the first player (the computer) reveals all instances of that letter in the word. Otherwise, the guess is wrong.
- The game ends either when all the letters in the word have been revealed or when the guesser has run out of guesses.
Your assignment is to design and write a computer program to play Hangman. In particular, your program should do the following:
- Read the file dictionary.txt, which contains over 120,000 words. You can store the words in a Python list.
- Choose a secret word from the word list at random. I suggest using the random.choice function.
- Prompt the user for a number of guesses, which must be an integer greater than zero. Don't worry about unusually large numbers of guesses after all, having more than 26 guesses is clearly not going to help your opponent! However, you should validate that the user enters a valid positive integer.
- Play a game of Hangman using the standard Hangman rules (see above), involves the following steps:
- Print out how many guesses the user has remaining, along with any letters the player has guessed and the current blanked-out version of the word.
- Prompt the user for a single letter guess, reprompting until the user enters a single letter that they have not guessed yet. Make sure that the input is exactly one character long and that it's a letter of the alphabet.
- Reveal the position of all occurrences of the guessed letter (if any) to the user.
- If the word doesn't contain any instances of the guessed letter, subtract one from the remaining guesses for the user. NOTE: a correct guess should not subtract from the remaining guesses
- If the player has run out of guesses, display the word that the computer picked.
If the player correctly guesses the word, congratulate them
dictionary.txt - Notepad File Edit Format View Help a aah aahed aahing aahs aal aalii aaliis aals aardvarkStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started