Question: In this project, you will simulate a simplified version of the game Blackjack. You will implement random card drawing, calculation, state tracking, and console input

In this project, you will simulate a simplified version of the game Blackjack. You will implement random card drawing, calculation, state tracking, and console input systems. The project is designed to be a playful yet practical opportunity to practice data types, console I/O, control structures, and modules.
A typical game will play out as follows:
The player will be dealt one card at the start of the game (where a game is one round of play). The player, based on the value of their cards, can either ask for another card (a hit) or choose to hold (stand). The dealer will then begin their turn and try to beat the players hand. The player is competing against the dealer, who has their own hand. Whomever is closer to 21 at the end of the game (as long as they dont exceed 21) wins the game.
1. Players turn: Player tries to reach or come close to 21 without going over (as 21 is the highest hand).
2. Dealers turn: Dealer tries to exceed the players hand without going over 21.
3. Determine the winner at the end of the game and increment the win count.
4. Repeat!
You will need a while loop in your program. The loop will allow you to play successive games without restarting the program each time; it will also allow you to keep a win count over multiple games.
Here is an example of a while loop:
The variable x is initialized to zero and the conditional statement is checked. Since x is less than 3502, the expression evaluates to true and the statement in the while loop block will be executed. The number 100 is added to the value of x, so x =100 now. Weve reached the end of the loop, so we jump back to the conditional statement. The expression evaluates to true. This repeats until x is not less than 3502.
In this project, you will need to loop until the player chooses the exit option from the menu.
If the player chooses to hold their hand (option 2), then the dealer will be dealt their hand. To determine the dealers hand, generate a random number between 16 and 26(both inclusive).
If the dealers hand is above 21, the player automatically wins. If both the dealer and player have the same value hand, then no one wins. In this case print It's a tie! No one wins!. Otherwise, whoever has the higher hand value wins the round. If the player wins, print You win!. If the dealer wins, print Dealer wins! After the winner (or tie) has been determined, a new game is started.
If the player chooses option 3, you will print the statistics of the game. Throughout your program you will need to keep track of the number of games played, the players number of wins, the dealer's number of wins and the number of ties. Print out all these values as well as the percentage of player wins to the total number games played. Format your percentage value to one decimal point. See sample output for format.
If option 4 is selected, exit the program.
If any other input is entered, print the following text:
Invalid input!
Please enter an integer value between 1 and 4.
Then, redisplay the menu. You can assume that the input will be numeric for this project (but not future projects).
Random Number Generation: p1_random.py (CLICK TO DOWNLOAD)
For random numbers, you must use the P1Random class in the p1_random module provided. First you must import the module, then you can create a P1Random variable inside main:
import p1_random as p1
rng = p1.P1Random()
# import the module (do this on the first line of code)
# create a P1Random variable
You can get a new int value between zero (0) inclusive, and some number (exclusive!) using the next_int() method:
my_number = rng.next_int(10) # Yields a random number in range [0,9]
To get a number in a specific range, use these commands:
my_number = rng.next_int(13)+1 # A random number in range [1,13]
my_value = rng.next_int(11)+16 # A random number in range [16,26]
NOTE: you must only pull random numbers as you need them, and you must use them in that order.
Do not get random values and throw them away! Do not get clever with how you generate random numbers! If you do, your output will diverge, and it could seriously impact your grade.
Example Output:
START GAME #1
Your card is a 5!
Your hand is: 5
1. Get another card
2. Hold hand
3. Print statistics
4. Exit
Choose an option: 1
Your card is a 8!
Your hand is: 13
1. Get another card
2. Hold hand
3. Print statistics
4. Exit
Choose an option: 1
Your card is a 2!
Your hand is: 15
1. Get another card
2. Hold hand
3. Print statistics
4. Exit
Choose an option: 1
Your card is a ACE!
Your hand is: 16
1. Get another card
2. Hold hand
3. Print statistics
4. Exit
Choose an option: 2
Dealer's hand: 24
Your hand is: 16
You win!
PLEASE MAKE SURE THAT I CAN COPY AND PAYSTE YOUR CODE
In this project, you will simulate a simplified

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Programming Questions!