• To begin, the player and the dealer are dealt an initial hand of two cards each.
  • If the dealer has Blackjack (the first two cards dealt total 21 points) and the player does not, the dealer automatically wins.
  • If the player has Blackjack (the first two cards dealt total 21 points) and the dealer does not, the player automatically wins.
  • If both the player and the dealer have Blackjack (the first two cards dealt total 21 points) then it is a push (draw).
  • If neither have Blackjack, then the player plays out his/her hand. Note that the term Blackjack can only be achieved as a result of the first two cards dealt.
  • When the player has finished playing out his/her hand, the dealer (in this case the computer) plays out the dealer's hand.
  • During the player's turn, the player is faced with two options either: 1. Hit (take a card): After the initial deal of two cards, a player may choose to receive additional cards as many times as he/she wishes, adding the point value of each card to his/her hand total. 2. Stand (end their turn): Do not receive any more cards. The players turn is over.
  • The player repeatedly takes a card until, the player chooses to stand, or the player busts (that is, exceeds a total of 21). The player's turn is over after deciding to stand or if he/she busts.
  • Once the player has finished, the dealer plays out his/her hand (in this case the computer), revealing the hidden second card amount. Note: the dealer always plays his/her hand regardless of what happens with the player's hand. The dealer must hit until he or she has a point value of 17 or greater. 5 of 31 Blackjack rules:
    • If the player busts, he/she loses even if the dealer also busts.
    • If the player and the dealer have the same point value, it is called a 'push' and neither win the hand (draw).
    • An initial two-card deal of 21 (an 11 plus a 10) is called Blackjack (i.e. an 11 plus a 10 is dealt as the very first hand) and wins the round automatically.
    • An Ace counts as eleven (11) points unless this would cause the player/dealer to bust, in which case it is worth one (1) point. House rules:
    • The dealer must hit until he or she has a point value of 17 or greater.
    • The player can not stand on a point value less than 15. The player with the higher hand that does not exceed 21 wins the game!

You do not have to write the code that deals one card at a time, a module containing the function that does that for you has been provided. The playing_cards.py file is a module that contains a function called deal_one_card() that deals one card at a time for you. The function returns a string (containing two characters) that represents a card; the first letter represents the face value of the card and the second letter represents the suit. For example: it may return the two character string 'AH', where A represents Ace and H represents Hearts; TC, where T represents Ten and C represents Clubs, 7S, where 7 represents the card value of 7 and S represents Spades, etc. You are required to use this as part of this assignment, however, please do not modify the playing_cards.py file.

#
# playing_cards module
# DO NOT MODIFY!
#

import random


# Deck of cards - first letter represents the face value and
# second letter represents the suit
deck = ['AH','2H','3H','4H','5H','6H','7H','8H','9H','TH','JH','QH','KH',
'AD','2D','3D','4D','5D','6D','7D','8D','9D','TD','JD','QD','KD',
'AS','2S','3S','4S','5S','6S','7S','8S','9S','TS','JS','QS','KS',
'AC','2C','3C','4C','5C','6C','7C','8C','9C','TC','JC','QC','KC']

# Playing deck in use
playing_deck = []


# Function to determine whether there are any cards left in the
# deck of playing cards
# Parameters: No parameters
# Returns: True if the deck is empty, False otherwise
def is_empty_deck():

# Check to see whether playing deck is empty
return len(playing_deck) == 0


# Function to rebuild and shuffle the deck
# Parameters: No parameters
# Returns: Nothing is returned from the function.
def reset_deck():
global playing_deck

# Create new playing deck
playing_deck = deck.copy()

# Shuffle deck
random.shuffle(playing_deck)


# Function to deal one card
# Parameters: No parameters
# Returns: A string (containing two characters) representing
# the card delt, i.e. '2H' meaning 2 of Hearts
def deal_one_card():

# Check to see whether there are any cards left
if is_empty_deck():

# Rebuild and shuffle deck
reset_deck()

# Return a card (string of two characters)
return playing_deck.pop(0)

Practical requirements (continued) Your solution MUST include the use of the following:

  • get_hit_choice() This function takes no parameters and returns the user's choice, whether to hit ('h) or stand (s). The function prompts for, reads and validates the users choice to either hit or stand.
  • get_play_choice(prompt_text) This function takes a string (the prompt text) to display to the screen as a parameter and returns the users choice, whether to play again, i.e. 'y' or n. The function prompts for, reads and validates the users choice to keep playing (y) or stop playing (n).
  • diplay_hand(hand_text, hand) This function takes a string (hand text) to display to the screen and a list of strings (hand) containing the cards dealt. The function does not return any values and displays the hand (list) to the screen in the following format, for example: If the player_hand list is as follows, player_hand = ['4D', 'TS', 'KD'] calling the display_hand() function like so display_hand('\nPlayer\'s hand is', player_hand) will produce the following output to the screen: Player's hand is 24: 4 of Diamonds | 10 of Spades | K of Diamonds
  • If the dealer_hand list is as follows, dealer_hand = ['KS', '9C'] calling the display_hand()function like so display_hand('\nDealer\'s hand is', dealer_hand) will produce the following output to the screen: Dealer's hand is 19: K of Spades | 9 of Clubs This function must call function
  • get_hand_total(hand). o get_hand_total(hand) This function takes a list of strings (containing the cards dealt) and calculates the point value of the hand. The function returns the total point value of the hand. 7 of 31
  • play_player_hand(player_hand) This function takes a list of strings (containing the cards dealt) and returns the total point value of the player's hand. The function plays out the players hand until the player either busts or chooses to stand. Do not let the player stand on a value less than 15 and display the player busts message if the player exceeds 21. The function must call the following functions: get_hit_choice(), get_hand_total(), display_hand() and deal_one_card().
  • play_dealer_hand(dealer_hand) This function takes a list of strings (containing the cards dealt) and returns the total point value of the dealer's hand. The function plays out the dealers hand until the dealer has a point value of 17 or greater. Display the dealer busts message if the dealer exceeds 21. The function must call the following functions: get_hand_total(), display_hand() and deal_one_card().
  • Output that strictly adheres to the assignment specifications. If you are not sure about these details, you should check with the 'Sample Output' provided at the end of this document.

Your solutions MUST NOT use: break, or continue statements in your solution. Do not use the quit() or exit() functions or the break or return statements (or any other techniques) as a way to break out of loops. Doing so will result in a significant mark deduction.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.