To start the game of Blackjack, players are dealt two cards at random from a shuffled deck.
You write the following code to simulate the act of dealing an initial hand. To test the code, you deal a hand times and record the number of times the player makes Blackjack on their first two cards. If the code is written correctly, what do you expect to find for , the fraction of initial hands that are Blackjack?
from random import shuffle
# define the card ranks, and suits
ranks = [_ for _ in range(2, 11)] + ['JACK', 'QUEEN', 'KING', 'ACE']
suits = ['SPADE', 'HEART ', 'DIAMOND', 'CLUB']
"""Return a new deck of cards."""
return [[rank, suit] for rank in ranks for suit in suits]
# get a deck of cards, and randomly shuffle it
deck = get_deck()
# issue the player and dealer their first two cards
player_hand = [deck.pop(), deck.pop()]
Assumptions and Details
- A two card hand is said to be "blackjack" if it consists of an Ace and any card worth 10 (i.e. a ten, or a face card).