Question
(PYTHON)Write a program to play a game blackjack (text only no graphics). Assume that the computer is the dealer and the player is the user.
(PYTHON)Write a program to play a game blackjack (text only no graphics). Assume that the computer is the dealer and the player is the user.
Overview of the game:
First the program selects hands of two cards each, one for the dealer and one for the player
Next it is the player's Turn While his/her hand is valued at under 21, he/she has the option of getting an additional card. However, any time that the player's hand is valued at 22 or more the game ends and the player loses.
Next it is the dealer's Turn (unless the player already lost) While the dealer's cards are worth 16 or less, the dealer draws a card. If the dealer's hand is worth 22 or more, the player wins
If dealer's hand is worth 21 or less and the player's hand is also worth 21 or less then the dealer's hand and the player's hand are compared and a winner is determined.
Scoring
If one of the following is true, the dealer wins:
The dealer has Black Jack (to be defined) or
The player's hand > 21
Else if one of the following is true, the player wins:
The player has Black Jack
The dealer's hand > 21
The player's hand > the dealer's hand
Else the dealer wins (if there is a tie or if the dealer's hand is worth more)
Some Assumptions
Suits (Clubs, Diamonds, Hearts, Spades) will be ignored
We will assume that there are only 13 different cards: ['A',2,3,4,5,6,7,8,9,10,'J','Q','K']
There can never be more than 4 of the same card type in play at any time. A good way of handling this is as follows:
Create a global variable that has 52 cards in it, e.g., deck_of_cards = ['A',2,3,4,5,6,7,8,9,10,'J','Q','K','A',2,3,4,5,6,7,8,9,10,'J','Q','K','A',2,3,4,5,6,7,8,9,10,'J','Q','K','A',2,3,4,5,6,7,8,9,10,'J','Q','K']
Write a function that randomly draws one card from that deck. The function should both select the card randomly and remove that card from the deck when it is drawn.
Use the .pop function to remove a card and return the card that you remove
If you provide .pop with an index it gets a card at that index
Select the index randomly, but never pick an index larger than the deck. Remember that every time you draw a card from the deck, the size of the deck gets smaller.
'A' can be worth either 1 or 11 points
If assuming that 'A' is worth 11 would make the hand higher than 21, it must equal 1 point
At the end of a hand, if assuming 'A' is worth 11 would result in a higher hand (but not above 21), it must be worth 11.
'A' must be worth 1 in a dealer's hand if:
the dealer does not have black jack and
assuming 'A' is worth 11 would cause the dealer to stop picking cards (the total is above 16) and
assuming it is worth 1 would allow the dealer to pick another card (the total is below 17)
2-10 are worth their face value (2 is worth 2, 3 is worth 3, etc.)
'J','Q' and 'K' are each worth 10 points
Black Jack is a hand consisting of 2 cards: an 'A' and a card worth 10 points
Other Program Details:
You should use the random module and lists to write this program
Hands of cards should be modeled as lists.
If the above rules vary slightly from the correct rules of Blackjack, it doesn't matter very much. Please focus more on the assignment than on the rules of Blackjack :).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started