A file will contain a list of candidate words, and one will be chosen at random. The user is then prompted for letters to guess. Correct guesses will be placed in the corresponding blanks; there is a limit to how many incorrect guesses are allowed.
An input file example might look something like this:
Here is a sample interface:
It would be very appropriate to have one execution of the program to allow a user to try to guess at more than one entry in the file.
Using Ascii art to sketch out the hanging man would be an interesting feature, but the more challenging part of the program is the game itself.
It is expected that there will be at least two distinct functions defined for this project. Each function's purpose should be summarizable in one or two sentences. a function should be fewer than 30 lines of code (or not much more than that), not counting documentation and blank lines.
Each function should have a meaningful name and meaningful parameters. Each should have a docstring (using triple quotes) at minimum describing what the function does. The complete interface should be clear from the function heading and its documentation.
The function certainly may define additional local variables to complete its task. The parameter list should only contain values and variables that must be shared with its caller, and no other hidden communications (such as no global variables).
If your submitted project design seems insufficient to these expectations, you are certainly permitted (and encouraged) to improve upon it, since that will help you to complete the program on time.
Use of Data Files
The data files are intended to allow a great deal more flexibility in the application areas without having to modify the program code. Each program is expected to get all of the content data from the data files. The content is not to be hard-coded into the Python code itself.
data file consists of the possible words
to be guessed at
The program should prompt the user for the name of the data file. Whether you require the user to type an extension (such as ".txt") or whether the program automatically adds the extension is up to you. You may assume that the user running the program knows the name of an existing data file in that same folder.
If you wish to remove that assumption, and give a user a list of choices of available files, you may do so, for 10% Extra Credit. This would require getting a list of files from the Operating System (consider the 'listdir' method in the 'os' module).
Your program should not make any particular assumptions about the exact size of the data file. It should just be able to read to the end of the file (the for loop can do that). A recent recitation demonstrated that it is rather easy to identify how many file lines were actually found, and the program can then make use of that number.
Here are a few things that would make the assigned projects a little interesting, with some hints about how to go about them.
The Extra Credit portion to the posted solution to Homework 5 built up a solution string one letter at a time, much in the same way as Hangman does. This modified answer is most easily done with a list, replacing letters into each position where it belongs, with the string join method allowing the answer to show up in a clean fashion.
Your program should take care of case-sensitivity, not treating 'a' and 'A' as separate letters. Whether your answers are all upper case or lower case is up to you -- just make sure that the user at the keyboard gets the appropriate responses.
At least three files will be submitted instead of just one.
Include at least these three items in your submission on Canvas:
There are a couple reasons for requesting multiple data files:
Your program should, of course, not be aware of the exact content of the files you submit. The graders should be free to make any change to the data file that might help them evaluate your program.