Answered step by step
Verified Expert Solution
Link Copied!

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:

  1. One player (the computer) chooses a secret word, then writes out a number of dashes (-, or _ underscore and space) equal to the word length.
  2. 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.
  3. 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:

  1. Read the file dictionary.txt, which contains over 120,000 words. You can store the words in a Python list.
  2. image text in transcribed
  3. Choose a secret word from the word list at random. I suggest using the random.choice function.
  4. 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.
  5. Play a game of Hangman using the standard Hangman rules (see above), involves the following steps:
  1. 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.
  2. 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.
  3. Reveal the position of all occurrences of the guessed letter (if any) to the user.
  4. 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
  5. 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 aardvark

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions