Course Home | Assignments | Class Photo | Computing Resources | Lab Hours/Tutoring | Schedule | Submit

Saint Louis University

Computer Science 150
Introduction to Object-Oriented Programming

Michael Goldwasser

Spring 2010

Dept. of Math & Computer Science

Programming Assignment 05

Hangman

Due: 11:59pm, Monday, 1 March 2010


Contents:


Overview

Your goal is to provide an implementation of the classic game Hangman, as outlined in Exercise 5.36 on page 201 of the text. More detailed requirements are given below.


Collaboration Policy

For this assignment, you are allowed to work with one other student if you wish (in fact, we suggest that you do so). If any student wishes to have a partner but has not been able to locate one, please let the instructor know so that we can match up partners.

Please make sure you adhere to the policies on academic integrity in this regard.


Detailed Requirements

The text gives an overview of the game. Here we make the following requirements explicit:

You may safely assume that the underscore character (_) does not appear in any of the secrets, and that each secret has at least one alphabetic character.


Picking the Secret

When originally developing your program, it will probably help for you to debug your software while relying on a known answer. That way you will be able to monitor whether the software behaves as is expected.

For the final product, we want a user to play the game without knowing the secret in advance. We offer the following function that allows the software to pick a secret uniformly at random from an underlying file of possibilities (assumed to have one entry per line).

We also offer a data file that contains the titles of over 1800 movies. We have placed the file on turing, or you may download it (movies.txt), if working on your own machine.

from random import randrange

def pickSecret(filename='/Public/goldwasser/150/programs/hangman/movies.txt'):
  secret = ''
  linenum = 0
  for word in file(filename):
    linenum += 1
    if randrange(0,linenum)==0:
       secret = word.strip()
  return secret

Note: the default filename used here is presuming that you want the movie list and that you are working on turing. You can provide some other filename by sending an explicit parameter.


An Example

As a demonstration of the various interactions, we offer this trace of a sample execution of the program.

Submitting Your Assignment

You should create a new file, hangman.py, that contains all of the code. This file must be submitted electronically.

You should also submit a separate 'readme' text file, as outlined in the general webpage on programming assignments. For this assignment, please explain any interesting design decisions that you made about the user interface or about your implementation techniques. If you worked as a pair, please make this clear and briefly describe the contributions of each person in the effort.

Please see details regarding the submission process from the general programming web page, as well as a discussion of the late policy.


Grading Standards

The assignment is worth 10 points.


Extra Credit

Use a graphical interface to animate a game in progress, rather than relying solely on the text-based interface.


Michael Goldwasser
Last modified: Monday, 15 February 2010