You are going to create a program to play a simplified version of the card game blackjack against a computer dealer. If you are unfamiliar with the card game read the sections entitled “How does blackjack work?” and “How to play blackjack for beginners” at this website: https://www.casino.org/blackjack/how-to-play/
ex07
folder an place it into your cs102
folderblackjack_logic.py
and blackjack.py
with ThonnyDOWNLOAD THE PATCHED TEST.PY FILE HERE
Hopefully you have already read the website to learn how to play blackjack or already understand the game. For this assignment we will keep track of the following pieces of data:
We will be using a simplified set of actions to make coding the game easier. The only actions a player (or the computer dealer) can perform during a round of blackjack are:
While this all sounds like a lot, you will only be required to implement eight functions that will make the blackjack.py program work. Each function has a comment that deatils the purpose of the function, what the parameters should be, and what to return as well as comments to help with implementation. USE THIS INFORMATION TO HELP YOU! The pass
statement means that the function simply does nothing as it is not implemented you should delete that statement when implementing the function.
A basic flowchart for the blackjack game can be found here.
The game has a primary loop that displays the player and dealers current money totals. From there, the player decides to either quit or make a bet. The player’s bet may not exceed the amount of money the player or dealer possesses. If the player quits, the game closes. Once the player’s bet is recorded, the deck is shuffled and cards are delt. The player can see only the first card delt to the dealer, the second is facedown and “hidden” from the player. Hidden cards are shown as a #
. The player can see all of their cards.
Once all cards are dealt, a player may either hit or stand. If a player chooses to stand their turn is over. When choosing to hit, a player is dealt a new card from the deck and their card value total is updated. If the player exceeds a value of 21, they bust or automatically lose the round. A player may hit as many times as they like until they choose to stand or they bust.
The dealer is a computer opponent who makes decisions based on simple logic. If the dealer’s hand value is:
The dealer wins if:
The players wins if:
After a winner is decided, the bet amount is subtracted from the loser and added to the winners money total. The game repeats in the fashion until the player decides to quit (not place a bet), reduces the dealers money to zero, or has no money left.
If the dealer or player have no money left, the game ends. If the player chooses to quit before then, the game also ends.
Right click your ex07
assignment folder and choose compress
on MacOS or Compress to ZIP file
on Windows. Upload the zip file to the matching Moodle assignment to submit your work.