This assignment should be written in the python programming language. You should only use python features that we have discussed up to this point. If you have questions about whether or not a particular feature can/should be used, ask the instructors! You may use any python version 3.0 or newer.
All of your programming should be well-formatted and easy for the graders to read and comprehend. Each program file should have a header comment at the top that has the following format:
#
# Author: Student Name
# Description:
# A short description of what this program does!
#
If any part of your scripts are particularly complex, you should put documentation comments above those lines of code.
In this assignment you will implement hangman in python. If you are not familiar with this game, see the wikipedia article linked above.
This implementation of hangman will be an interactive command-line interface game.
Name the script hangman.py
.
There will be two players (player 1 and player 2).
Player 1 will be responsible for choosing the word for player 2 to guess at the beginning of the game.
This is the only time that player 1 will input information to the program.
For the remainder of the program run, player 2 will be responsible for inputting letter guesses to the program. If player 2 guesses a correct letter, the program will update and will report the player’s current guessing progress. If the player guesses and incorrect letter, a body part will be added to the hangman, and then the program will ask for another letter.
When you first start up hangman, you will see:
HANGMAN: Welcome to HANGMAN!
HANGMAN: player 1 Enter a hangman word:
At this point, player 1 should type in a word which player 2 will have to guess the letters of, and press enter. The word that player 1 inputs should have only lower-case letters a-z (you may assume this). After this, it will be up to player 2 to guess the word, letter-by-letter. When player 2 guesses letters, the player will also only type lower-case letters.
For example:
HANGMAN: Welcome to HANGMAN!
HANGMAN: player 1 Enter a hangman word: ant
HANGMAN: Wrong guesses left: 6
HANGMAN: Word progress: ___
HANGMAN: player 2 guess a letter:
Player 2 is responsible for guessing the letters to spell out “ant”. Before each letter guess prompt, hangman will report the player’s current status. Specifically, it will report the number of wrong guesses remaining (starts at 6) and the word progress.
Let’s say player 2 guesses ‘r’, then ‘d’, then ‘e’, all of which are not in the word “ant”. This is how the game should respond:
HANGMAN: Welcome to HANGMAN!
HANGMAN: player 1 Enter a hangman word: ant
HANGMAN: Wrong guesses left: 6
HANGMAN: Word progress: ___
HANGMAN: player 2 guess a letter: r
HANGMAN: NOPE!
HANGMAN: Wrong guesses left: 5
HANGMAN: Word progress: ___
HANGMAN: player 2 guess a letter: d
HANGMAN: NOPE!
HANGMAN: Wrong guesses left: 4
HANGMAN: Word progress: ___
HANGMAN: player 2 guess a letter: e
HANGMAN: NOPE!
HANGMAN: Wrong guesses left: 3
HANGMAN: Word progress: ___
HANGMAN: player 2 guess a letter:
...
As you can see, at each wrong guess the “Wrong guesses left” value decreased. At this point player 2 only has three guesses left before losing (which would add the other arm and both legs).
From here, the user might guess a few correct words, say ‘a’ and ‘n’:
...
HANGMAN: player 2 guess a letter: a
HANGMAN: YES!
HANGMAN: Wrong guesses left: 3
HANGMAN: Word progress: a__
HANGMAN: player 2 guess a letter: n
HANGMAN: YES!
HANGMAN: Wrong guesses left: 3
HANGMAN: Word progress: an_
HANGMAN: player 2 guess a letter: t
HANGMAN: YES!
HANGMAN: Wrong guesses left: 3
HANGMAN: Word progress: ant
HANGMAN: player 2 wins!
...
In each of these cases, no guesses were removed, because they were all correct! The correctly guessed letters were added to the blanks (underscore). Player 2 has almost won. The player only needs to guess the last letter (‘t’). Winning from this point would look like:
...
HANGMAN: player 2 guess a letter: t
HANGMAN: YES!
HANGMAN: Wrong guesses left: 3
HANGMAN: Word progress: ant
HANGMAN: player 2 wins!
Once the player wins the program will exit.
On the other hand, a losing sequence after the user had guessed ‘r’, ‘d’, ‘e’, ‘a’, and ‘n’ would look like:
...
HANGMAN: player 2 guess a letter: x
HANGMAN: NOPE!
HANGMAN: Wrong guesses left: 2
HANGMAN: Word progress: an_
HANGMAN: player 2 guess a letter: y
HANGMAN: NOPE!
HANGMAN: Wrong guesses left: 1
HANGMAN: Word progress: an_
HANGMAN: player 2 guess a letter: z
HANGMAN: NOPE!
HANGMAN: Wrong guesses left: 0
HANGMAN: Word progress: an_
HANGMAN: player 1 wins!
Again, the program exists at this point.
Several example games will be provided in the diff-testing tool. We will be testing with the same examples, so make sure your program matches the diff-test output.
The word that player 1 inputs for player 2 to guess should be a single word with no spaces. You do not have to handle this error. You may assume player 1 behaves as expected.
Also, you can assume that players 2 will only ever guess one character at a time. You do not have to add error handling for the edge cases (though, you can if you want to).
I recommend that you lists or sets (or both) to store the guessed letters.
There are examples in the diff-tester of how to handle the case where player two guesses the same letter multiple times.
This assignment requires printing out precise text messages and notifications. As already mentioned, it is important to be precise when doing these printouts.
We will only take minimal points off for very minor differences (for example, minor character spacing issues). However, we will take points off for any non-trivial differences, so try to be as precise as you can!
It is due on Tuesday, 8/9/2017, at 7:00pm. You may not use any late days since it is the last day of class!
You should put all of your code in to a python file named hangman.py
.
Submit hangman.py
to the associated D2L dropbox.
Following these turn-in and naming instructions closely is very important, because our grading scripts will depend on some of the details.
You may lose points if these instructions are not followed precisely!