CS 484 - Artificial Intelligence
Fall 2007


Loyola College > Department of Computer Science > CS 484 > Labs & Projects > Lab 0

Due

Thursday, September 13th at the beginning of class.
Lab will be penalized 20% for each class meeting after the due date.

THIS LAB WILL BE DONE INDIVIDUALLY.

Introduction

In this lab you will be writing a text based version of hangman. The purpose of this lab is introduce you to the language features of python, so I will include some design suggestions below if you would like to use them. For this lab, you will write a class Hangman which has class variables to keep track of the state of the game and a few methods to support playing the game. At the beginning of a game, a random word should be choosen from this dictionary. The user will begin with 6 lives, which are used when a user guesses a letter which is not part of the word. As the game progresses, letters in the word are filled in when the user guesses a letter that is in the word. The game ends when there are no more letters to guess or all of the lives have been used. What follows is a sample interaction with the game. The program you produce should be similiar to the following:
snoopy[~/CS484]  python hangman.py
You have 6 lives remaining
The word is:  ______
The following letters have already been guessed:  []
Enter a letter: a
a is not in the word
You have 5 lives remaining
The word is:  ______
The following letters have already been guessed:  ['a']
Enter a letter: b
b is not in the word
You have 4 lives remaining
The word is:  ______
The following letters have already been guessed:  ['a', 'b']
Enter a letter: b
Letter has already been guessed.
Enter a new letter: c
c is not in the word
You have 3 lives remaining
The word is:  ______
The following letters have already been guessed:  ['a', 'b', 'c']
Enter a letter: d
d is not in the word
You have 2 lives remaining
The word is:  ______
The following letters have already been guessed:  ['a', 'b', 'c', 'd']
Enter a letter: e
e is not in the word
You have 1 life remaining
The word is:  ______
The following letters have already been guessed:  ['a', 'b', 'c', 'd', 'e']
Enter a letter: f
f is not in the word
Sorry you lose
Do you want to play again? (y/n) y
You have 6 lives remaining
The word is:  ______
The following letters have already been guessed:  []
Enter a letter: a
a is not in the word
You have 5 lives remaining
The word is:  ______
The following letters have already been guessed:  ['a']
Enter a letter: e
e is not in the word
You have 4 lives remaining
The word is:  ______
The following letters have already been guessed:  ['a', 'e']
Enter a letter: i
i is not in the word
You have 3 lives remaining
The word is:  ______
The following letters have already been guessed:  ['a', 'e', 'i']
Enter a letter: o
o is in the word
You have 3 lives remaining
The word is:  ____o_
The following letters have already been guessed:  ['a', 'e', 'i', 'o']
Enter a letter: t
t is in the word
You have 3 lives remaining
The word is:  __t_o_
The following letters have already been guessed:  ['a', 'e', 'i', 'o', 't']
Enter a letter: h
h is in the word
You have 3 lives remaining
The word is:  __tho_
The following letters have already been guessed:  ['a', 'e', 'i', 'o', 't', 'h']
Enter a letter: n
n is in the word
You have 3 lives remaining
The word is:  __thon
The following letters have already been guessed:  ['a', 'e', 'i', 'o', 't', 'h', 'n']
Enter a letter: p
p is in the word
You have 3 lives remaining
The word is:  p_thon
The following letters have already been guessed:  ['a', 'e', 'i', 'o', 't', 'h', 'n', 'p']
Enter a letter: y
y is in the word
You guessed it!  The word is python
Do you want to play again? (y/n) n
snoopy[~/CS484]

Requirements

To run the program you will type "python <filename>"

What to turn in