This assignment is primarily python. 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!
When grading your assignments, each problem/script/function will be thoroughly tested with many types of input, so make sure you test your scripts/functions well!
The python in this assignment will be graded using python 3.6, and tests will be run on a Mac machine. In general python works well cross-platform, but if you want to be absolutely sure your program works as expected, test on a mac! Any python version 3.4 or newer should suffice though.
All of your scripts should be well-formatted and easy for the graders to read. Each script should have a header comment at the top that has the following format:
#
# Author: Student Name
# Description:
# A short description of what this program / script / set of functions does!
#
Each function in your script(s) should have a descriptive comment above it. 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:
$ python3 hangman.py
GAME: Welcome to HANGMAN!
GAME: 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, may have upper or lower case alphabetical letters. Internally, it should be converted to all lower case. When player 2 guesses letters, the player may type lower and upper case letters. Since the word player 1 specified was converted to lower-case, the guessed letters should also be converted internally. After this, it will be up to player 2 to guess the word, letter-by-letter.
For example:
$ python3 hangman.py
GAME: Welcome to HANGMAN!
GAME: player 1 Enter a hangman word:
ant
GAME: Current hangman status:
___
GAME: 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. Initially the status is very simple because no body parts have been added to the hangman, and no letters have been guessed.
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:
...
GAME: Current hangman status:
___
GAME: player 2 guess a letter:
r
GAME: NOPE!
GAME: Current hangman status:
_
|_|
___
GAME: player 2 guess a letter:
d
GAME: NOPE!
GAME: Current hangman status:
_
|_|
|
|
___
GAME: player 2 guess a letter:
e
GAME: NOPE!
GAME: Current hangman status:
_
|_|
--|
|
___
GAME: player 2 guess a letter:
As you can see, at each wrong guess a new body part was added to the man. 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’:
...
GAME: player 2 guess a letter:
a
GAME: YES!
GAME: Current hangman status:
_
|_|
--|
|
a__
GAME: player 2 guess a letter:
n
GAME: YES!
GAME: Current hangman status:
_
|_|
--|
|
an_
GAME: player 2 guess a letter:
In each of these cases, no new body parts were added to the hangman, but 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:
...
GAME: player 2 guess a letter:
t
GAME: YES!
GAME: Current hangman status:
_
|_|
--|
|
ant
GAME: 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:
...
GAME: player 2 guess a letter:
q
GAME: NOPE!
GAME: Current hangman status:
_
|_|
--|--
|
an_
GAME: player 2 guess a letter:
x
GAME: NOPE!
GAME: Current hangman status:
_
|_|
--|--
|
/
an_
GAME: player 2 guess a letter:
z
GAME: NOPE!
GAME: Current hangman status:
_
|_|
--|--
|
/ \
an_
GAME: player 1 wins!
$
Again, the program exists at this point.
If the same letter is guessed more than once, you should not notify the user. If it was a correct guess, continue as normal. If it was an incorrect guess, this should still count as a “wrong” guess and a body part should be added to the hangman. Below are some examples of duplicating guesses:
$ python3 hangman.py
GAME: Welcome to HANGMAN!
GAME: player 1 Enter a hangman word:
tiger
GAME: Current hangman status:
_____
GAME: player 2 guess a letter:
g
GAME: YES!
GAME: Current hangman status:
__g__
GAME: player 2 guess a letter:
g
GAME: YES!
GAME: Current hangman status:
__g__
GAME: player 2 guess a letter:
$ python3 hangman.py
GAME: Welcome to HANGMAN!
GAME: player 1 Enter a hangman word:
zebra
GAME: Current hangman status:
_____
GAME: player 2 guess a letter:
x
GAME: NOPE!
GAME: Current hangman status:
_
|_|
_____
GAME: player 2 guess a letter:
x
GAME: NOPE!
GAME: Current hangman status:
_
|_|
|
|
_____
GAME: player 2 guess a letter:
x
GAME: NOPE!
GAME: Current hangman status:
_
|_|
--|
|
_____
GAME: player 2 guess a letter:
Below are several animated examples of a complete hangman game session:
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).
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!
This problem will be graded out of 100 points.
This was assigned on Friday, February 24, 2017. It is due Friday, March 3, 2017, at 6:00pm.
Turn-in instructions:
.py
file in a directory named netid-assignment-6
where netid
is your netid. Make sure only the .py
file(s) exist in this directory, no others.netid-assignment-6
directory. The result should be named netid-assignment-6.zip
.
There are instructions online for how to do this with a Mac and how to do this with a PC.
Make sure to zip the directory, not the file(s) individually!netid-assignment-6.zip
to the assignment-6 D2L dropbox.Following these turn-in 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!