Blackjack, what are the chances?

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 \(10^6\) 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 \(\hat{f}_\text{blackjack}\), the fraction of initial hands that are Blackjack?

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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']

def get_deck():
    """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()
shuffle(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).
×

Problem Loading...

Note Loading...

Set Loading...