Assignment 1
Chuck-a-Luck Game
due Sunday January 21
Motivation
The goal of this assignment is to write a program that lets the user play a game of Chuck-a-Luck. You should become familiar with conditional statements, loops, and Python modules such as random. This is also a good example of how a flow chart and pseudocode can help in planning a program.
Task
The game is simple. The player bets on a number from 1 through 6. The dealer then rolls three dice. If one of the dice matches the number the player bet on, the payoff is 1 to 1, meaning if the player bet $5 he gets $10 back, thus profiting $5. If two dice match the number, the payoff is 2 to 1, if all three dice match the number, the payoff is 3 to 1.
Details
Your program will start with $10 in the bank (the player's money).
It will first ask player the question, "You have $[bank_balance], how much do you want to bet?" The prompt will accept any number from $0 to $[bank balance]. If the user chooses $0, the program will quit with the following announcement, "Congratulations! You have chosen to quit with $[bank balance] in the bank." In all cases, [bank balance] should be replaced with the actual dollar amount in the bank.
If the user chooses any number between $0 and $[bank balance], your program will ask the user to choose a number between 1 and 6 (inclusive). If an invalid number is entered, the question should be asked again. Otherwise, your program will simulate rolling three dice (by generating random numbers) and will show user following result, "The three numbers rolled are $Num1, $Num2, $Num3, you [win/lose] $X. Your new bank balance is $Y." After that, if the bank balance is positive, you ask the first question again. If the bank balance is $0, you quit and display the following message, "I am sorry, but your bank balance is zero dollars. Good bye!"
If the user enters an amount larger than bank balance, the program will show the message, "I am sorry, you cannot bet more than your bank balance." After that, it should prompt the user for again for his/her bet.
The game continues until the player chooses to quit or loses all his/her money. You can assume that all numbers entered by the user are integers. For this assignment, it is recommended that you draw a flow chart and write pseudocode before starting to write the actual code.
Assignment submission details
- Place all of your code in a file called Game_<UCID>.py (where <UCID> corresponds to your UCSD e-mail address). For instance jsmith@ucsd.edu would turn in Game_jsmith.py
- At the start of the file, write your name in comments. Also write a short explaintaion of how your program works, highlighting any assumptions you made about the problem, experiments you ran to show that the code worked, and anything else you want to communicate about the assignment.
- Attach this file to an e-mail message addressed to cg8w1@icogsci1.ucsd.edu with the subject "<UCID> Game.py"
- Send the email no later than Sunday, January 21 at 11:59 pm.
Hints/Recommendations
- Look at the documentation for the random module to make sure that you are using the best function for the job. http://docs.python.org/modindex.html
- If you are having trouble understanding keyboard input, see section 4.13 in the text.
- Accomplish earlier steps before attempting later ones!
- Make sure the code you submit is well documented, since this will make it more likely the graders will understand what you were trying to do.
- If you get stumped before you finish the entire assignment:
- document your accomplishments.
- describe the problem that stopped you, what you tried, what confused you, etc.