Project 2 - A Slot Machine
Due - Friday, March 2, 2007
The goal of this project is to give you experience using
iteration and lists. You will write a slot machine program similar to what you might find in Las Vegas. There are lots of websites that allow you to play similar games online. You are encouraged to visit those sites to get a feel for how such a program should work.
This project is divided into three parts. You will complete the parts in order. For each part, I have specified the percentage it will contribute to the final project grade. For example, part 1 is worth 75%. That means that if you only complete part 1, you are still eligible to receive a C on the project.
Part 1 - 75%
For part 1, you will implement a main control loop that will execute until the user decides to stop playing the game. As long as the user wishes to continue, you will spin by selecting three random numbers in the range 0-9 and placing them in a list. You will display the list for the user and determine whether the user is a winner. For this portion of the project, a win occurs if the user has spun three of the same number. You will report a win or loss to the user and ask if she would like to spin again. You will also keep track of the total number of wins and losses and report each value to the user when she exits the program.
At minimum, you must implement the following functions:
- spinAgain - This function takes no input and returns True if the user would like to spin again and False otherwise. It will ask the user whether she would like to spin again, verify the response, and return the appropriate result.
- spin - This function takes no input and returns a list containing three random numbers in the range 0-9.
- displaySpin - This function takes as input a list and displays its contents for the user.
- determineWin - This function takes as input a list and returns True if all items in the list are the same and False otherwise.
Part 2 - 10%
For part 2, you will implement a simplified betting system. The user will start with 100 credits. For each loss, one credit is deducted. For each win, one credit is added. The play will stop if the user chooses not to spin again or if the user has gone bust (run out of credits).
Part 3 - 15%
For part 3, you will allow the user to bet 1, 2, or 3 credits for each spin. If a user does not spin three of the same number, she loses her bet. If she does spin three of the same number, she receives credit according to the following payout chart. For example, a user who bets 2 credits and spins 888 will receive a payout of 400 credits.
Spin | 1 credit | 2 credit | 3 credit |
999 | 300 | 600 | 900 |
888 | 200 | 400 | 600 |
777 | 100 | 200 | 300 |
666 | 50 | 100 | 150 |
555 | 40 | 80 | 120 |
444 | 20 | 40 | 60 |
333 | 10 | 20 | 30 |
222 | 5 | 10 | 15 |
111 | 2 | 4 | 6 |
000 | 1 | 2 | 3 |
Implementation Requirements and Hints
- Points will be deducted for poor design. You should, for example, consider using additional functions to implement parts 2 and 3.
- For full credit on part 3, use one or more lists to keep track of the payout chart.
Due 1:30PM Friday March 2, 2007
- Complete and submit your working code. Turn in a hard copy in class and place a copy of your .py file in the submit directory /home/submit/cs110-s07/username.
- Make sure that each function is well documented. Your documentation should specify the type and function of the input parameters and output.
- Run your program on a variety of inputs ensuring that all error conditions are handled correctly.
Note: No portion of your code may be copied from any other
source including another text book, a web page, or another
student (current or former). You must provide citations for any
sources you have used in designing and implementing your program.
Sami Rollins