I have divided the README into two sections:
- The first section includes instructions from the Guardian coding exercises.
- The second section details the structure of my code.
- create a single deck of playing cards
- two players (called Sam and the Dealer) who will play against each other
- each player is given two cards from the top of a shuffled deck of cards
- determine score of a hand1
- check if either player has blackjack (21) with their initial hand and wins the game
- if neither player has blackjack then Sam can start drawing cards from the top of the deck
- Sam should stop drawing cards from the deck if their total reaches 17 or higher
- Sam has lost the game if their total is higher than 21
- when Sam has stopped drawing cards the Dealer can start drawing cards from the top of the deck
- the Dealer should stop drawing cards when their total is higher than Sam.
- the Dealer has lost the game if their total is higher than 21
- determine which player wins the game
Updated Aug 28, 2023
I used an object-oriented programming structure to create the program
How I did this task:
- Imported the random module
- Created the following classes: Deck, Hand, Card, and Game
- Deck: shuffle the cards and get the deck ready
- Hand: calculate the value (card score)
- Card: present both the card and value
- Game: run the game in the command line
Footnotes
-
Numbered cards are their point value. Jack, Queen and King count as 10 and Ace counts as 11. ↩