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 106 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 f^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
fromrandomimportshuffle# define the card ranks, and suitsranks=[_for_inrange(2,11)]+['JACK','QUEEN','KING','ACE']suits=['SPADE','HEART ','DIAMOND','CLUB']defget_deck():"""Return a new deck of cards."""return[[rank,suit]forrankinranksforsuitinsuits]# get a deck of cards, and randomly shuffle itdeck=get_deck()shuffle(deck)# issue the player and dealer their first two cardsplayer_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).
Your answer seems reasonable.
Find out if you're right!