CS21 Lab 6: Slot Machine

Due 11:59pm Fri, March 8

Run update21, if you haven't already, to create the cs21/labs/06 directory. Then cd into your cs21/labs/06 directory and create the python program for lab 6 in this directory (handin21 looks for your lab 6 assignments in your cs21/labs/06 directory):


$ update21
$ cd ~/cs21/labs/06
$ pwd
  /home/your_user_name/cs21/labs/06

Your programs are graded on both correctness and style. Please review the comments regarding programming style on the main page.

Slot machine

Write a program called slotmachine.py that allows the user to play a simplified slot machine. In this program all users start with $10 and each play costs $2. The user may play the machine as long as they want, if they have enough money.

Our simplified slot machine will have three reels, where each reel has four possible symbols: heart, bar, lemon, star. For a single play, the winnings are as follows:

Therefore, since it costs $2 to play, the user will only gain money if all three reels match.

Here is a sample run of the slotmachine program:


$ python slotmachine.py

Welcome to SlotMachine v0.1
---------------------------
It costs $2 to play.
If all 3 reels match, you get $5.
If all 3 reels are HEARTS, you get $50!
If 2 reels match, you get $2. 
Otherwise...you get nothing!

------------------------------

You have $10 left in your wallet
play the slots? [quit or Play]: play
*******************************
*** lemon -- heart -- lemon ***
*******************************
two symbols match...you win $2
------------------------------

You have $10 left in your wallet
play the slots? [quit or Play]: zebra
play the slots? [quit or Play]: play
*******************************
*** lemon --  bar  -- heart ***
*******************************
L-O-S-E-R
------------------------------

You have $8 left in your wallet
play the slots? [quit or Play]: play
*******************************
*** heart -- heart -- heart ***
*******************************
winner! ($50)
------------------------------

You have $56 left in your wallet
play the slots? [quit or Play]: quit

Thanks for playing!
Requirements, hints, and tips...

$ python slotmachine.py

Welcome to SlotMachine v0.1
---------------------------
It costs $2 to play.
If all 3 reels match, you get $5.
If all 3 reels are HEARTS, you get $50!
If 2 reels match, you get $2. 
Otherwise...you get nothing!

------------------------------

You have $10 left in your wallet
play the slots? [quit or Play]:       <-- user hit Enter key here
**********************************
*** orange --  heart --  heart ***
**********************************
two symbols match...you win $2
------------------------------

You have $10 left in your wallet
play the slots? [quit or Play]: 
**********************************
***   star --  heart --  heart ***
**********************************
two symbols match...you win $2
------------------------------

You have $10 left in your wallet
play the slots? [quit or Play]: 
**********************************
***  lemon -- orange --    bar ***
**********************************
L-O-S-E-R
------------------------------

You have $8 left in your wallet
play the slots? [quit or Play]: quit

Thanks for playing!
Extensions

If you want an extra challenge, just for fun (no points), try these:

Submit
Once you are satisfied with your programs, hand them in by typing handin21 at the Linux prompt.

You may run handin21 as many times as you like, and only the most recent submission will be recorded. This is useful if you realize, after handing in some programs, that you'd like to make a few more changes to them.