Question: This assignment will give you more experience on the use of: 1. Functions 2. iteration 3. string in PYTHON Your program must meet the following

This assignment will give you more experience on the use of:

1. Functions

2. iteration

3. string in PYTHON

Your program must meet the following specifications. Note that control gets complex to play this game: I had 3 while loops and almost 20 if statements.

1. Your program must prompt for an initial players bank balance (from which wagers will be subtracted or added). Note that all dollar amounts in this game will be ints.

2. Before each game (i.e. before the first roll of the game) prompt the user for a wager. Wagers must be less than or equal to the bank balance. If not, keep asking for a wager until a valid one is entered. (Hint: use a while loop).

3. One game is played with a sequence of two dice rolls. A game can end after one roll of the two dice (e.g. a 7 was rolled) or it can continue with an unlimited number of rolls (Hint: use a while loop). Note that the rules are different on the first roll of the game than on subsequent rolls. (Hint: use a Boolean to indicate that it is the first roll, e.g. I used one named first_roll that was initially True and after the first roll was changed to False and not changed for the subsequent rolls of the game.)

4. After you play each game update the players bank balance by adding or subtracting the wager depending on whether they won or lost.

5. Prompt the user to see if they want to play another game. If yes, play another game. (Hint: use a while loop).

6. If the user is to play another game, prompt the user to see if they wish to add to their balance. If yes, then prompt for a value and update the players bank balance.

7. You have to use the ten functions in the provided proj04.py skeleton. You have to implement and use the

a. display_game_rules(): We provide this function.

b. get_bank_balance(): Prompt the player for an initial bank balance (from which wagering will be added or subtracted). The player-entered bank balance is returned as an int.

c. add_to_bank_balance(balance): Prompts the player for an amount to add to the balance. The balance is returned as an int.

d. get_wager_amount(): Prompts the player for a wager on a particular roll. The wager is returned as an int.

e. is_valid_wager_amount(wager, balance): Checks that the wager is less than or equal to the balance; returns True if it is; False otherwise.

f. roll_die(): Rolls one die. This function should randomly generate a value between 1 and 6 inclusively and returns that value as an int. Use the randint() function called as randint(1,6) for this project. We provide the import at the top of the file. (For Mimir testing the default is to use the cse231_random library which isnt actually random but generates specific test cases. To actually play the game comment out the cse231 version and use the actual Python random.)

g. calculate_sum_dice(die1_value, die2_value): Sums the values of the two die and returns the sum as an int.

h. first_roll_result(sum_dice): The function determines the result on the first roll of the pair of dice. A string is returned. You are required to use at least one Boolean operator or or and in this function (I used 4).

i. If the sum is 7 or 11 on the roll, the player wins and "win" is returned. ii. If the sum is 2, 3, or 12 on the first throw (called "craps"), the player loses (i.e. the "house" wins) and "loss" is returned. iii. If the sum is 4, 5, 6, 8, 9, or 10 on the first throw, then the sum becomes the player's "point" and "point" is returned. i. subsequent_roll_result(sum_dice, point_value): The function determines the result on the subsequent rolls of the pair of dice. A string is returned. i. If sum_dice is the point_value, then point is returned ii. If sum_dice is 7, then loss is returned iii. Otherwise, neither is returned.

j. main(): Takes no input. Returns nothing. Call the functions from here. That, the game is played in this function.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The question is quite detailed and specifies a programming assignment in Python with clear requireme... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!