CS 150 - Assignment 6 - Hangman

Due: Wednesday 4/12 at the beginning of class

For this lab, you will be implementing a text-based version of hangman. There are many variants of the program, so make sure to follow the specifications closely. You can also play a demo version of the program you will be implementing. See the prelab for details on how to do this.

Make sure you read through this whole handout first before getting started. I've given an overview of how to proceed and some hints near the end.

If you want, you may work with a partner on this lab. If you do, you must both be there whenever you're working on the lab. Only one of you should submit the assignment, but make sure both your names on in the comments.

Playing the game

When the program starts it reads a file containing a list of possible words. You can download a text file with CS words here:
Right click on the link and select "Save link as..." to download. Remember, this file needs to be in the same directory as your program.

After reading the file, the program randomly selects one of these words as the word that the user is trying to guess and then displays the following:

Guessed letters: 
Incorrect guesses left: *******
Word: _______
This display has three main components:
  1. Guessed letters: Shows the letters the player has guessed so far. The letters will be separated by a space and should be all capitalized. When the game starts, no letters have been guessed, so this area is blank.
  2. Incorrect guesses left: Shows the remaining number of wrong/incorrect guesses the player has before the game is over. Each remaining guess is represented as an '*'. In this version of the game, the player starts out with 7 incorrect guesses.
  3. Word: This shows the word that the player is trying to guess. Each underscore (_) represents a letter in the word. The word above is 7 letters long. As the user plays, the correctly guessed letters will be filled in.
The program runs by repeatedly prompting the user for the next letter. When the user enters a letter, there are three possible cases: The following transcript shows all three of these different situations happening as the game is being played:
Guessed letters: 
Incorrect guesses left: *******
Word: ____

Guess a letter: e
Guessed letters: E 
Incorrect guesses left: *******
Word: _e__

Guess a letter: a
Guessed letters: A E 
Incorrect guesses left: *******
Word: _ea_

Guess a letter: r
Guessed letters: A R E 
Incorrect guesses left: ******
Word: _ea_

Guess a letter: s
Guessed letters: A S R E 
Incorrect guesses left: *****
Word: _ea_

Guess a letter: a
Letter already guessed!
Guess a letter: s
Letter already guessed!
Guess a letter: t
Guessed letters: A S R E T
Incorrect guesses left: ****
Word: _ea_

Guess a letter:
The game ends when either the user runs out of guesses, in which case the word is shown:
The word was: heap
Better luck next time!
or if the user fills in all of the underscores in the word, then the user wins and the number of incorrect guesses is printed out:
Guessed letters: A H S R E 
Incorrect guesses left: *****
Word: hea_

Guess a letter: p
You win!
The word was: heap
You guessed it with 2 incorrect guesses

Implementation requirements

Besides following the game specification described above, your program MUST meet the following requirements:

One path to implementation

There are many different ways to implement your program, but here is one suggestion: Hints: Here are some things to think about:

Extra points

As always, you may add any additions to the program for extra points as long as it doesn't make the program easier. Make sure to put in comments at the top of the file indicating any extra points that you implement. Here are some ideas that you might consider:

When you're done

Make sure that your program is properly commented: In addition, make sure that you've used good style.

Submission procedure

Submit your .py file online using the digital submission link on the course web page. You must have submitted it online before the beginning of class on Wednesday. If you worked with a partner, please submit only one copy, but make sure both people's names are at the top of the submitted file.


Four functions implemented as specified 4
All words are read from the file 1
Each time a random word is picked from the file 1
Initial underscored word shown correctly 1
Each guess is inserted appropriately in underscored word    2
Guessed letters correctly displayed 2
Guessed letters are updated appropriately 1
Guessed letters uses a set 1
Repeated requests from user on repeated letter 2
Incorrect guesses updated appropriately 2
Game ends correctly on win 1
Game ends correctly on lose 1
Handles lower and uppercase letters 1
Program starts automatically on run 1
Comments, style 5
Prelab 2
Extra points 2
Total 28 + 2