Programming Assignment 3

Hangman

Due: Monday, March 2 at 11:59pm (via email)


Contents:


Overview

The goal of this assignment is to write a program which simulates the classic game, Hangman.

See Exercise  5.36 on page. 201 for more detailed requirements. In addition to those requirements, please try to do the following:

The one drawback to our game right now is that someone needs to type in the secret word, but presumably that shouldn't be the same person who is guessing. In the long run, we will learn how to open up a file of words and randomly select one, but for now, we'll give the snipet of code that is required for this behavior. (The filename used here is presuming you are working on turing - it could be adjusted accordingly.)

from random import *

def pickSecret(filename='/home/faculty/echambe5/Public/movies.txt'):
  choices = file(filename)
  secret = ''
  linenum = 0
  for word in choices:
    linenum += 1
    if randrange(0,linenum)==0:
       secret = word.strip()
  return secret

You may safely assume that the underscore character (_) does not appear in any of the secrets.

Note: If you would like to use this file on some machine other than turing, feel free to download it (movies.txt) and save it on your own machine.


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.


Submitting Your Assignment

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


Extra Credit

Use graphics creatively to animate a game in progress.