CMSC 201

Homework 8 - Due 11/14

This homework must be submitted by 5pm on the due date to get any credit.

For HW8, you will write a simple 2 player word guessing game. The purpose of this homework is for you to use the top-down design skills that you have learned in lecture to create a well modularized program. Your main can be up to 50 lines of code (the less the better) and you need to have at least 8 functions (you can have more). Each function should perform a well-defined task (e.g. open the file, print out the score, print out who won the game, etc.). Take time to draw a top-down design diagram and write some pseudocode instead of going straight to the computer. Once you have a good design, start to code. Here is how the game will work:
  1. Your program will open a text file that has a list of words in it (one per line).
  2. Each round of the game consists of reading a word and displaying _ instead of the characters in the word. The round will end when all the _ have been replaced by actual letters.
  3. Starting with Player 1, players will take turn guessing a letter (it should not be case sensitive; or are both the same letter). If the letter is there, the player will get one point per occurrence of the letter and get to go again. If a player guesses a letter that has already been guessed (does not matter if it is actually in the word or not), they will lose 1 point and it will become the next player's turn. If a player guesses a letter that is not there (but has not been guessed before), it will become the next player's turn but they will not lose a point. During the letter guessing process, if a player types a character that is not a letter (e.g. 1,$,#) or if more than one letter (e.g. hello) is entered, just reprompt; there is no point penalty.
  4. When it is time to guess a letter, your program needs to display the characters (always in upper case) that have already been found and _ for characters that are left to be found, whose turn it is, and the score.
  5. There will be as many rounds as there are words in the file (e.g. if there are 3 words in the file, there will be 3 rounds). The players whose turn it was when one round was finished, starts the next one.
  6. The program will end when all rounds have been played and a message will be displayed to announce the winner or a draw (in addition to the Final score). The player with highest number of points wins. Use the samples below as a guide for developing your program and for the format of the prompts and the outputs. Don't add anything extra and create your program to exactly match the specifications given above and in the samples.

Sample run 1


bash-4.1$ cat wordFile1.txt 
book 
bash-4.1$ python hw8.py
Enter the name of your word file: wordFile1.txt
Round: 1 

_ _ _ _ 

Player 1's turn 
---------------- 
The Score for Player 1 is: 0 
The Score for Player 2 is: 0 
---------------- 

Enter a letter: b

B _ _ _ 

Player 1's turn 
---------------- 
The Score for Player 1 is: 1 
The Score for Player 2 is: 0 
---------------- 

Enter a letter: a
No letter: A in the word 

B _ _ _ 

Player 2's turn 

---------------- 
The Score for Player 1 is: 1 
The Score for Player 2 is: 0 
---------------- 

Enter a letter: o

B O O _ 

Player 2's turn 
---------------- 
The Score for Player 1 is: 1 
The Score for Player 2 is: 2 
---------------- 

Enter a letter: q
No letter: Q in the word 

B O O _ 

Player 1's turn 
---------------- 
The Score for Player 1 is: 1 
The Score for Player 2 is: 2 
---------------- 

Enter a letter: k

B O O K 

THE FINAL SCORE IS: 
---------------- 
The Score for Player 1 is: 2 
The Score for Player 2 is: 2 
---------------- 

The game is a draw 

Sample Run 2


bash-4.1$ cat wordFile.txt
UMBC 
python 
bash-4.1$ python hw8.py
Enter the name of your word file: wordFile.txt
Round: 1 

_ _ _ _ 

Player 1's turn 
---------------- 
The Score for Player 1 is: 0 
The Score for Player 2 is: 0 
---------------- 

Enter a letter: s
No letter: S in the word 

_ _ _ _ 

Player 2's turn 
---------------- 
The Score for Player 1 is: 0 
The Score for Player 2 is: 0 
---------------- 

Enter a letter: T
No letter: T in the word 

_ _ _ _ 

Player 1's turn 
----------------
The Score for Player 1 is: 0 
The Score for Player 2 is: 0 
---------------- 

Enter a letter: m

_ M _ _ 

Player 1's turn 
---------------- 
The Score for Player 1 is: 1 
The Score for Player 2 is: 0 
---------------- 

Enter a letter: S
The letter S has already been selected 

_ M _ _ 

Player 2's turn 
---------------- 
The Score for Player 1 is: 0 
The Score for Player 2 is: 0 
---------------- 

Enter a letter: cat
Enter a letter: 4
Enter a letter: c

_ M _ C 

Player 2's turn 
----------------
The Score for Player 1 is: 0 
The Score for Player 2 is: 1 
---------------- 

Enter a letter: b

_ M B C 

Player 2's turn 
---------------- 
The Score for Player 1 is: 0 
The Score for Player 2 is: 2 
---------------- 

Enter a letter: a
No letter: A in the word 

_ M B C 

Player 1's turn 
---------------- 
The Score for Player 1 is: 0 
The Score for Player 2 is: 2 
---------------- 

Enter a letter: u

U M B C 

Round: 2 

_ _ _ _ _ _ 

Player 1's turn 
---------------- 
The Score for Player 1 is: 1 
The Score for Player 2 is: 2 
---------------- 
Enter a letter: s
No letter: S in the word 

_ _ _ _ _ _ 

Player 2's turn 
---------------- 
The Score for Player 1 is: 1 
The Score for Player 2 is: 2 
---------------- 

Enter a letter: t 

_ _ T _ _ _ 

Player 2's turn 
---------------- 
The Score for Player 1 is: 1
The Score for Player 2 is: 3 
---------------- 

Enter a letter: p

P _ T _ _ _ 

Player 2's turn 
---------------- 
The Score for Player 1 is: 1 
The Score for Player 2 is: 4 
---------------- 

Enter a letter: n

P _ T _ _ N 

Player 2's turn 
---------------- 
The Score for Player 1 is: 1 
The Score for Player 2 is: 5 
---------------- 

Enter a letter: a
No letter: A in the word 

P _ T _ _ N 

Player 1's turn 
---------------- 
The Score for Player 1 is: 1 
The Score for Player 2 is: 5 
---------------- 

Enter a letter: y

P Y T _ _ N 

Player 1's turn 
---------------- 
The Score for Player 1 is: 2 
The Score for Player 2 is: 5 
---------------- 

Enter a letter: $
Enter a letter: h

P Y T H _ N 

Player 1's turn 
---------------- 
The Score for Player 1 is: 3 
The Score for Player 2 is: 5 
---------------- 

Enter a letter: q
No letter: Q in the word 

P Y T H _ N 

Player 2's turn 
---------------- 
The Score for Player 1 is: 3 
The Score for Player 2 is: 5 
---------------- 

Enter a letter: Y
The letter Y has already been selected 

P Y T H _ N 

Player 1's turn 
---------------- 
The Score for Player 1 is: 3 
The Score for Player 2 is: 4 
---------------- 

Enter a letter: a
The letter A has already been selected 

P Y T H _ N 

Player 2's turn 
---------------- 
The Score for Player 1 is: 2 
The Score for Player 2 is: 4 
---------------- 

Enter a letter: o 

P Y T H O N 

THE FINAL SCORE IS: 
---------------- 
The Score for Player 1 is: 2 
The Score for Player 2 is: 5 
---------------- 

Player 2 WINS! 

When you've finished your homework, use the submit command to submit the file. You must be logged into your account and you must be in the same directory as the file you're trying to submit. At the Linux prompt, type

submit cs201 HW8 hw8.py

After entering the submit command shown above, you should get a confirmation that submit worked correctly:

Submitting hw8.py...OK

If not, check your spelling and that you have included each of the required parts and try again.

You can check your submission by entering:

submitls cs201 HW8

You should see the name of the file that you just submitted, in this case hw8.py v