COMP 141 Spring 2018
Program 7: Wheel of Fortune
Assigned: Friday, April 8
Due: Sunday, April 15, 2018 by 11:55pm
You will write a program for two people to play a simplified game of
Wheel of Fortune.
Wheel of Fortune is a game-show variation on the
traditional word game hangman.
In this simplified version, Player 1 will pick a secret phrase, and Player 2 will guess letters
until they have guessed every letter in the phrase.
Here are the details:
- Player 1 enters a secret phrase at the keyboard.
- Player 2 then has an unlimited number of turns to guess all the letters
in the secret phrase, winning money for each correct consonant and having to pay
money for each vowel.
- Before each turn, player 2 spins the "wheel" to pick an amount of money that
each correct consonant will be worth (pick a random number between 1 and 100 using
random.randint(1, 100).
- If player 2 wants to guess a consonant, they earn an amount of money equal
to the spin value of the wheel
multiplied by how many times the consonant occurs in the puzzle. For example,
if they spin a 20 and guess the letter "c" and the puzzle has two c's, they win
$40. If the puzzle has no c's, they don't win or lose anything.
- If player 2 wants to guess a vowel, the spin value of the wheel is ignored, and
instead, player 2 is charged 10 dollars for every time their vowel appears in
the puzzle. So if the player spins a 20 on the wheel, they guess the letter "a,"
and the puzzle has three a's, then they are charged $30 (the 20 spin is ignored).
- The game ends when all the letters are filled in.
- The user should be prevented from guessing the same letter more than once
in a puzzle.
What you need to do
You must write a program that will prompt the user to enter a secret phrase,
then let "player 2" (in reality, you will play for both players) guess letters until
they win.
You must follow these steps:
- Download this pseudocode to get started. (The next
two parts refer to functions in the pseudocode you will write.)
- Write the function called make_puzzle_string. This function is designed to
turn the secret phrase into a "puzzle string" where all the letters that have not been
guessed yet are replaced with underscores. This is useful for displaying the
puzzle to the user throughout the game. Hint: This is a string transformation!
- Write the function called count_letter. This function is designed to count the number
of times a letter occurs in the secret phrase. This is useful for calculating how much
money someone will win or lose for a certain letter. Hint: this is a counting operation
(not surprisingly)!
- Test these functions to make sure they work. I highly recommend trying many sample
calls to your functions from the Python shell.
- Write the main function, following the pseudocode.
You may assume everything typed in by the players is in lowercase.
You may assume that the player's money value is allowed to drop into the negatives
(if they buy too many vowels). A challenge problem (see below) is to prevent this.
Sample Interaction
(What the user types is in bold.)
(Program begins)
Enter a phrase: too hot to hoot
Puzzle is: ___ ___ __ ____
You have 0 dollars so far.
Consonants are worth 4 dollars.
Enter a letter: t
There are 4 t's.
You get 16 dollars.
Puzzle is: t__ __t t_ ___t
You have 16 dollars so far.
Consonants are worth 57 dollars.
Enter a letter: a
Letter not in the puzzle.
Puzzle is: t__ __t t_ ___t
You have 16 dollars so far.
Consonants are worth 46 dollars.
Enter a letter: t
You already guessed that letter. Enter a letter: o
You bought a vowel for 10 dollars each.
There are 6 o's.
You spend 60 dollars.
Puzzle is: too _ot to _oot
You have -44 dollars so far.
Consonants are worth 8 dollars.
Enter a letter: h
There are 2 h's.
You get 16 dollars.
You win!
You won -28 dollars total!
The phrase was too hot to hoot.
(Program ends)
Another sample run:
(Program begins)
Enter a phrase: rhodes college
Puzzle is: ______ _______
You have 0 dollars so far.
Consonants are worth 30 dollars.
Enter a letter: l
There are 2 l's.
You get 60 dollars.
Puzzle is: ______ __ll___
You have 60 dollars so far.
Consonants are worth 11 dollars.
Enter a letter: c
There are 1 c's.
You get 11 dollars.
Puzzle is: ______ c_ll___
You have 71 dollars so far.
Consonants are worth 98 dollars.
Enter a letter: r
There are 1 r's.
You get 98 dollars.
Puzzle is: r_____ c_ll___
You have 169 dollars so far.
Consonants are worth 36 dollars.
Enter a letter: h
There are 1 h's.
You get 36 dollars.
Puzzle is: rh____ c_ll___
You have 205 dollars so far.
Consonants are worth 22 dollars.
Enter a letter: e
You bought a vowel for 10 dollars each.
There are 3 e's.
You spend 30 dollars.
Puzzle is: rh__e_ c_lle_e
You have 175 dollars so far.
Consonants are worth 69 dollars.
Enter a letter: g
There are 1 g's.
You get 69 dollars.
Puzzle is: rh__e_ c_llege
You have 244 dollars so far.
Consonants are worth 36 dollars.
Enter a letter: o
You bought a vowel for 10 dollars each.
There are 2 o's.
You spend 20 dollars.
Puzzle is: rho_e_ college
You have 224 dollars so far.
Consonants are worth 89 dollars.
Enter a letter: d
There are 1 d's.
You get 89 dollars.
Puzzle is: rhode_ college
You have 313 dollars so far.
Consonants are worth 8 dollars.
Enter a letter: s
There are 1 s's.
You make 8 dollars.
You won 321 dollars!
The phrase was rhodes college.
(Program ends)
What to Do
Create a Python program named yourlastname_yourfirstname_prg7.py
Include the standard program header at the top of your Python file.
Follow the comment guide to correctly comment your code.
Submit your Python file on Moodle under Program 7.
Requirements
When I examine your program, it should satisfy the following requirements.
Your program file is named correctly and it includes the standard program header.
You include a main function.
You prompt Player 1 for a secret phrase.
You correctly write the code for make_puzzle_string.
You correctly write the code for count_letter.
You write a loop that allows the user to continue to play until the puzzle is solved.
At each iteraction of the loop you: show the puzzle and show how much money the user has so far.
At each iteraction of the loop you: spin the wheel to decide how much consonants are worth.
At each iteraction of the loop you: prompt the user to guess a letter.
At each iteraction of the loop you: tell the user if their letter isn't in the puzzle and how much money they won or spent if it is.
At the end of the game, you tell the user how much money they won.
You comment your code appropriately (particularly your functions), use appropriate variable names, and your code must be neatly and clearly formatted and include proper use of 'white space'.
Challenge Questions (you may earn up to 5 points)
These are difficult and should only be attempted after all of the above specifications are working correctly.
- On the TV show, the wheel has a BANKRUPT space on it. If the player lands on that
space, they lose all their money (and don't get to guess a letter). Implement this in your program
(pick a percentage that this will come up, such as 5% of the time).
- On the TV show, if the player thinks they know the answer to the puzzle before
all the letters are filled in, they may guess the whole phrase at once to end the game immediately
(assuming they guess correctly, of course). Implement this in your program, so the user may choose to
guess the entire phrase once they think they know it, rather than making them guess each letter individually.
- On the TV show, there are three players each playing against each other.
Make your program work with three players as follows:
Each player has their own amount of money.
If the letter a player guesses is correct (it occurs in the secret phrase), they get to keep guessing letters until
they guess wrong. Then play passes to the next player.
- Let the program work with uppercase or lowercase letters.
- Prevent the player from buying a vowel unless they have enough money to pay for it.
Grading
Your program will be graded on correctness, as well as on coding style, which refers to choices you make when writing your code, such as good use of variable names,
appropriate indentation, and comments (this is not an exhaustive list). See the syllabus for further grading details.
You will receive one bonus point for every complete day your program is turned in early, up to a maximum of five points. For instance, if your program is due on September 20 at 11:59pm, if you turn in your code on Moodle any time on September 19 from 12:00am through 11:59pm, you will receive one extra point on your project. Programs submitted on September 18 from 12:00am through 11:59pm will receive two points. This pattern continues for up to five points.