Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Requirements Here are the requirements for your game: The computer must select a word at random from the list of available words that was provided
Requirements
Here are the requirements for your game:
The computer must select a word at random from the list of available words that was provided in words.txt The functions for loading the word list and selecting a random word have already been provided for you in pshangman.py
The game must be interactive; the flow of the game should go as follows:
At the start of the game, let the user know how many letters the computer's word contains.
Ask the user to supply one guess ie letter per round.
The user should receive feedback immediately after each guess about whether their guess appears in the computer's word.
After each round, you should also display to the user the partially guessed word so far, as well as letters that the user has not yet guessed.
Some additional rules of the game:
A user is allowed guesses. Make sure to remind the user of how many guesses she has left after each round. Assume that players will only ever submit one character at a time AZ
A user loses a guess only when she guesses incorrectly.
If the user guesses the same letter twice, do not take away a guess instead, print a message letting them know they've already guessed that letter and ask them to try again.
The game should end when the user constructs the full word or runs out of guesses. If the player runs out of guesses she "loses" reveal the word to the user when the game ends.
Sample Output
The output of a winning game should look like this...
Loading word list from file...
words loaded.
Welcome to the game, Hangman!
I am thinking of a word that is letters long.
You have guesses left.
Available letters: abcdefghijklmnopqrstuvwxyz
Please guess a letter: a
Good guess: a
You have guesses left.
Available letters: bcdefghijklmnopqrstuvwxyz
Please guess a letter: a
Oops! You've already guessed that letter: a
You have guesses left.
Available letters: bcdefghijklmnopqrstuvwxyz
Please guess a letter: s
Oops! That letter is not in my word: a
You have guesses left.
Available letters: bcdefghijklmnopqrtuvwxyz
Please guess a letter: t
Good guess: ta t
You have guesses left.
Available letters: bcdefghijklmnopqruvwxyz
Please guess a letter: r
Oops! That letter is not in my word: ta t
You have guesses left.
Available letters: bcdefghijklmnopquvwxyz
Please guess a letter: m
Oops! That letter is not in my word: ta t
You have guesses left.
Available letters: bcdefghijklnopquvwxyz
Please guess a letter: c
Good guess: tact
Congratulations, you won!
And the output of a losing game should look like this...
Loading word list from file...
words loaded.
Welcome to the game Hangman!
I am thinking of a word that is letters long
You have guesses left
Available Letters: abcdefghijklmnopqrstuvwxyz
Please guess a letter: a
Oops! That letter is not in my word:
You have guesses left
Available Letters: bcdefghijklmnopqrstuvwxyz
Please guess a letter: b
Oops! That letter is not in my word:
You have guesses left
Available Letters: cdefghijklmnopqrstuvwxyz
Please guess a letter: c
Oops! That letter is not in my word:
You have guesses left
Available Letters: defghijklmnopqrstuvwxyz
Please guess a letter: d
Oops! That letter is not in my word:
You have guesses left
Available Letters: efghijklmnopqrstuvwxyz
Please guess a letter: e
Good guess: e e
You have guesses left
Available Letters: fghijklmnopqrstuvwxyz
Please guess a letter: f
Oops! That letter is not in my word: e e
You have guesses left
Available Letters: ghijklmnopqrstuvwxyz
Please guess a letter: g
Oops! That letter is not in my word: e e
You have guesses left
Available Letters: hijklmnopqrstuvwxyz
Please guess a letter: h
Oops! That letter is not in my word: e e
You have guesses left
Available Letters: ijklmnopqrstuvwxyz
Please guess a letter: i
Oops! That letter is not in my word: e e
Sorry, you ran out of guesses. The word was else.
On the next page, we'll break down the problem into logical subtasks, creating helper functions you will need to have in order for this game to work.
We'll start by writing simple functions that will help us easily code the Hangman problem. First, implement the function isWordGuessed that takes in two parameters a string, secretWord and a list of letters, lettersGuessed. This function returns a boolean True if secretWord has been guessed ie all the letters of secretWord are in lettersGuessed and False otherwise.
Example Usage:
secretWord 'apple'
lettersGuessed eikprs
printisWordGuessedsecretWord lettersGuessed
False
Step 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