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 IO 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 at the end of the game as long as they dont exceed wins the game.
Players turn: Player tries to reach or come close to without going over as is the highest hand
Dealers turn: Dealer tries to exceed the players hand without going over
Determine the winner at the end of the game and increment the win count.
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 the expression evaluates to true and the statement in the while loop block will be executed. The number is added to the value of x so x 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
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 then the dealer will be dealt their hand. To determine the dealers hand, generate a random number between and both inclusive
If the dealers hand is above the player automatically wins. If both the dealer and player have the same value hand, then no one wins. In this case print Its 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 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 is selected, exit the program.
If any other input is entered, print the following text:
Invalid input!
Please enter an integer value between and
Then, redisplay the menu. You can assume that the input will be numeric for this project but not future projects
Random Number Generation: prandom.py CLICK TO DOWNLOAD
For random numbers, you must use the PRandom class in the prandom module provided. First you must import the module, then you can create a PRandom variable inside main:
import prandom as p
rng pPRandom
# import the module do this on the first line of code
# create a PRandom variable
You can get a new int value between zero inclusive, and some number exclusive using the nextint method:
mynumber rngnextint # Yields a random number in range
To get a number in a specific range, use these commands:
mynumber rngnextint # A random number in range
myvalue rngnextint # A random number in range
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 #
Your card is a
Your hand is:
Get another card
Hold hand
Print statistics
Exit
Choose an option:
Your card is a
Your hand is:
Get another card
Hold hand
Print statistics
Exit
Choose an option:
Your card is a
Your hand is:
Get another card
Hold hand
Print statistics
Exit
Choose an option:
Your card is a ACE!
Your hand is:
Get another card
Hold hand
Print statistics
Exit
Choose an option:
Dealer's hand:
Your hand is:
You win!
PLEASE MAKE SURE THAT I CAN COPY AND PAYSTE YOUR CODE
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
