Compsci 6, Spring 2012, Hangman How-to
Hangman guidlines and requirements.
You will snarf some code. You will create a module named
Hangman.py and write code in that module only.
Your program must consist of functions and function calls. There can be
no global variables in your program.
Your program must be robust in the face of user errors, but don't worry
too much about that.
The user should have the choice of deciding the length of the word and
the number of misses allowed.
- You'll need import modules
in the module you write:
The sample output on the assignment writeup
page should be generically followed in that the user should
see a representation of the secret word with guesses filled in,
the letters used so far, and so on.
We'll supply more guidelines in terms of function parameters and return
types as part of class and walkthroughs.
- Functions should be brief/short, ideally 10-20 lines,
but that's a guideline, not a requirement.
- Functions that do more than one thing are candidates to be
divided into function calls doing the more than one thing. A
prime candidate is the play function, it will consist
of picking letters, updating word-displays, determining if the
game should continue, validating input, and so on. In principle, each
of these will be a different function, though in practice
that's often not possible.
- A function should minimize its side-effects. Changing one
parameter and returning a value are ok. Changing multiple
parameters and returning a value should be avoided, though
sometimes this is ok too -- have a justification for the
code you write.
- Use good function and parameter names.
- You should think about the use-cases for the state in the
program, that will help you decide what types to use. For
example, if you use a string for what's shown as
__ __" then you'll need to create a new string when the
first and last letters are both 't' since strings are
immutable. But ifyou use a list, e.g.,
["__", "__", "__",
"__"] then you can change list elements and simply
print the string that corresponds to the list, e.g., by using
" ".join(xyz) Python idiom.