Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python 3.0+ Black Jace Dice Game with Help commands The rules are fairly simple,

ID: 667981 • Letter: P

Question

Python 3.0+ Black Jace Dice Game with Help commands

The rules are fairly simple, you roll dice and total them for your score. The player who

has the highest total without going over 21 wins.

Each round begins with the dealer rolling 2 dice and outputting the total. The program will then

roll 2 dice for the user and show them the total as well. The user is then given the option of

rolling a single die and adding that to their total. They may continue rolling a die for as long as

they want to continue, or until they go over 21. Once the user is done, if they haven’t gone over

21 the dealer will continue to roll a die until they bust or tie/beat the player.

The program will start by asking the user for how much money they want in chips. This amount

must be greater than 0. Before each round it should ask them for their wager amount. The

wager is more than 0 and less than or equal to their pot. If the user wins a round their wager

gets added to their pot. If they lose, then the pot is decremented by the wager. If there is a tie,

then the pot is left alone. The player continues playing until they run out of money. In which

case they can begin play again by buying more chips or quitting.

Requirements

Your program will ask the user for an initial amount of money that the user will have.

This is their pot. They are allowed to keep playing as long as they have money left. The

user cannot enter a value <= 0. It must be a positive whole number. Do not worry about

the user entering floats or strings. We’ll learn how to deal with those later.

You should ask them how much they want to wager for each round. This amount has to

be greater than zero, and less than or equal to the amount they have left. Keep

prompting them for a correct amount until they have provided it. Again, we won’t worry

about the user entering anything malicious at this point.

The pot and wager will be integers.

Once the initial rolls are made, ask the user if they want to roll another die. The only

acceptable values are Y,YES,N or NO. Any other input give a warning and prompt for

input again.

The user rolls a single die as long as they want to and it gets added to their total. If they

bust ( go over 21), then they will not be asked to roll again and automatically lose.

Once the user loses all their money ( which is inevitable ), you should report how many

rounds played before they lost all their money, and the maximum amount of money they

had.

Once the user runs out of money ask the user if they want to play again. Valid

responses are Y, YES, N or NO. If they want to play more, then they can enter another

pot amount. If no, then the program ends.

If the user plays again don’t forget to reset the rounds played and maximum amount.

Development notes

To roll the dice, you need a way to generate random numbers. Fortunately, Python

includes just such a feature. To use it, make the first line of 'real' code (after your

opening comments):

import random

To generate a random whole number from 1 to 6:

d = random.randint(1,6)

Obviously, you can use whatever variable name you like other than d.

The string method .lower() produces a new string that is the lowercase version of a

string.

'ABC'.lower() == 'abc'

It can be useful in processing some of the user input. Its

use is not required.

There is also a .upper() method as well. ‘abc’.upper() produces ‘ABC’

The membership operator in can be useful as well. Its use is not required

Example. Take notice of the bad input.

>>> ================================ RESTART ================================

>>>

Welcome to Blackjack Dice

Enter the amount of money you want in chips. ==> $

-1

The amount must be greater than 0

Enter the amount of money you want in chips. ==> $

0

The amount must be greater than 0

Enter the amount of money you want in chips. ==> $

10

Enter the amount you want to wager. ==> $

-1

The wager must be greater than zero

Enter the amount you want to wager. ==> $

12

The wager cannot be greater than the amount you have in the pot

Enter the amount you want to wager. ==> $

5

Dealer rolled a 6 and a 2 for a total of 8

You rolled a 4 and a 5 for a total of 9

Do you want to roll again? (Y,YES,N,NO) ==>

e

You must enter Y,YES,N or NO

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 6 for a total of 15

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 3 for a total of 18

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 6 for a total of 24

You busted, I'm so sorry

The dealer won this round, you've lost your $ 5 wager

You now have $ 5 in the pot

Enter the amount you want to wager. ==> $

5

Dealer rolled a 1 and a 1 for a total of 2

You rolled a 6 and a 6 for a total of 12

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 5 for a total of 17

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 3 for a total of 20

Do you want to roll again? (Y,YES,N,NO) ==>

n

You stayed on 20

The Dealer rolled 2 for a total of 4

The Dealer rolled 4 for a total of 8

The Dealer rolled 6 for a total of 14

The Dealer rolled 4 for a total of 18

The Dealer rolled 2 for a total of 20

You tied the dealer, it's a push

You now have $ 5 in the pot

Enter the amount you want to wager. ==> $

1

Dealer rolled a 2 and a 1 for a total of 3

You rolled a 3 and a 1 for a total of 4

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 4 for a total of 8

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 4 for a total of 12

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 4 for a total of 16

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 6 for a total of 22

You busted, I'm so sorry

The dealer won this round, you've lost your $ 1 wager

You now have $ 4 in the pot

Enter the amount you want to wager. ==> $

1

Dealer rolled a 3 and a 6 for a total of 9

You rolled a 3 and a 4 for a total of 7

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 3 for a total of 10

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 6 for a total of 16

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 1 for a total of 17

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 1 for a total of 18

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 1 for a total of 19

Do you want to roll again? (Y,YES,N,NO) ==>

n

You stayed on 19

The Dealer rolled 2 for a total of 11

The Dealer rolled 3 for a total of 14

The Dealer rolled 2 for a total of 16

The Dealer rolled 2 for a total of 18

The Dealer rolled 1 for a total of 19

You tied the dealer, it's a push

You now have $ 4 in the pot

Enter the amount you want to wager. ==> $

1

Dealer rolled a 4 and a 5 for a total of 9

You rolled a 4 and a 2 for a total of 6

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 4 for a total of 10

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 3 for a total of 13

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 3 for a total of 16

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 5 for a total of 21

Do you want to roll again? (Y,YES,N,NO) ==>

n

You stayed on 21

The Dealer rolled 3 for a total of 12

The Dealer rolled 1 for a total of 13

The Dealer rolled 5 for a total of 18

The Dealer rolled 6 for a total of 24

Congratulations, you won $ 1

You now have $ 5 in the pot

Enter the amount you want to wager. ==> $

5

Dealer rolled a 5 and a 2 for a total of 7

You rolled a 1 and a 1 for a total of 2

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 5 for a total of 7

Do you want to roll again? (Y,YES,N,NO) ==>

y

You rolled a 2 for a total of 9

Do you want to roll again? (Y,YES,N,NO) ==>

n

You stayed on 9

The Dealer rolled 4 for a total of 11

The dealer won this round, you've lost your $ 5 wager

You now have $ 0 in the pot

You ran out of money

You played 6 rounds. Your highest pot was 10

Do you want to play again? (Y,YES,N,NO) ==>

e

You must enter Y, YES, N or NO

Do you want to play again? (Y,YES,N,NO) ==>

n>>>

Explanation / Answer

import random pot = 0 wager_loop_restart = 'y' wager = 0 type_of_bet = '' number_guess = -1 play_again = 'y' play_again_loop_restart = 'y' s_rand = -1 e_rand = -1 o_rand = -1 pot_initialized = 'n' game_loop_restart = 'y' rounds = 0 high_amount_calc = [pot] extra_info = " Roulette is a game where you have a pot(total money to bet with), a wager(the amount you are betting in a specific hand), The type of bet (Straight-any number, Even-only even number, Odd-only odd numbers), and the number slot where you think the roulette wheel will drop the ball in (win/lose). The roulette wheel will then spin and if the ball lands in the slot you guessed then you win the odds based on the type of bet. Straight wins 35, loses 1. Even wins 1, loses 1. Odd wins 1, loses 1. " extra_info_input = '' high_amount = 0 amount_began_game_with = 0 #while loop to keep game restarting automatically while game_loop_restart == 'y': ##once the user puts a cash value amount in the pot, they can't add any to the pot for the rest of the game, so when pot is initialized with a value, the pot is unaccessable if pot_initialized == 'n': ##before the game starts we ask if the user wants to learn more about Roulette before starting. extra_info_input = input("Enter 'H' to learn more about the game of Roulette before beginning. ").lower() if extra_info_input == 'h': print(extra_info) ##if the user enters anything but 'h', we just move on to the game and they'd have to restart the python program to see it again. elif extra_info_input != 'h': print("I guess we'll move on then... ") pot = int(input("Enter a pot amount ==> ")) ##while the pot value input that the user gives is not greater than 0, keep prompting them for this information. while pot pot: print("The amount you are wagering cannot be more than pot amount") wager = int(input("Enter an amount to wager ==> ")) type_of_bet = input("What type of bet would you like to make? (S)traight, (E)ven, or (O)dd.").lower() ##if the user chooses the straight type bet, do the following code... if type_of_bet == 's': ##Prompt the user for an even number number_guess = int(input("Enter a number between 0 and 36 ==> ")) ##is the even number guessed within the correct range?? while number_guess >= 0 and number_guess = 2 and number_guess 0: pot -= 1 ##sort all the high pot amount values high_amount_calc.sort() ##pop off the last value on the list, which is the greatest numeric value and set it equal to a variable 'high_amount' high_amount = high_amount_calc.pop() ##read the numeric value currently in the 'pot' variable and let the user know how much money they have left to play with in their pot. print("You have $"+str(pot)+" left.") play_again = input("Do you want to play again? ==> ").lower() if play_again_loop_restart == 'y': ##if the user has entered 'n' to discontinue playing the game, then we execute the following code... if play_again == 'n': ##by setting the below variable equal to 'n', we ensure that the encapsulating loop which restarts the game will not run anymore. game_loop_restart = 'n' ##when we got the pot value initially from the user, we set this value equal to another variable called 'amount_began_with' to keep track if the user ever gets higher than what they started with ## in their pot. if high_amount != amount_began_game_with: ##You played [this number of rounds], and had a high pot value of [this much]... print("You played a total of "+str(rounds)+" and had a high amount of "+str(high_amount)) print(" Game Over... ") break ##If the user's end pot value is below what they started with then we dont give them any updated news, but just remind them that they didnt make any profit.. elif high_amount == amount_began_game_with: ##You played [this number of rounds], and had a high pot value of [this much]... print("You played a total of "+str(rounds)+" and your highest pot amount was what you started with.") print(" Game Over... ") ##break out of the elif loop break ##break out of the if loop break else: ##if the user entered 'n' for not continuing the game, then set a variable 'play_again_loop_restart' equal to 'n' so that its condition is false and it doesnt run again. play_again_loop_restart = 'n' ##If play_again is set to true, then we give 'number_guess' the value outside it's conditional range which will break the enclosing loop and restart the sequence above. if play_again == 'y': ##reset all loop values wager_loop_restart = 'y' wager = 0 type_of_bet = '' number_guess = -1 play_again = 'y' play_again_loop_restart = 'y' s_rand = -1 e_rand = -1 o_rand = -1 number_guess = 37