More simulations

Download notebook Interact

Simulation exercises

import numpy as np

Penalty shootout technique

Jen is the penalty taker for her football team.

She’s been doing this for a long time. She thinks she normally has a 80% chance of scoring.

In the last 15 penalties she has taken, she has been trying a new technique. She scored on all 15 penalties.

How certain can she be that this would not have happened, using the old technique?

Aim big

John is playing Monopoly. His piece, the top hat, is sitting in a really bad spot, just in front of some expensive hotels. He is about to roll the two 6-sided die. He needs a score of 10 or more to skip over the hotels. What are John’s chances?

Solve by simulation.

Hint: consider np.random.randint. Read the help with np.random.randint?.

Blackjack

Given any three random playing cards, what is the chance that the ranks of the three cards add up to 21?

10, jack, queen and king all count as 10. For example, one way of getting 21 is a seven, a four and a king.

Simple version

Assume the three cards are each dealt from the top of a full shuffled deck. Therefore, the procedure is:

  • you shuffle, look at the top card, record the rank, you put it back.
  • repeat twice more.

Assume that the ace counts as 1. What are the chances of getting a total rank of 21?

Hint: start with this array:

ranks = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10])

Investigate np.random.choice to use this array for the problem.

Less simple version

Assume the cards are drawn as they were for the problem above.

Now the ace can count as 1 or as 11, whichever gives a total of 21. Now what are the chances of a total rank of 21?

Hint: you can change values of 1 to 11 like this:

# Make an example array
some_cards = np.array([1, 3, 5, 1, 2, 10, 1, 4])
some_cards
array([ 1,  3,  5,  1,  2, 10,  1,  4])
# Make a Boolean array that has True for positions where some_cards == 1
card_eq_1 = some_cards == 1
card_eq_1
array([ True, False, False,  True, False, False,  True, False])
# In the found positions, change the value to 11
some_cards[card_eq_1] = 11
some_cards
array([11,  3,  5, 11,  2, 10, 11,  4])

You might want to use this kind of trick more than once in your solution.