1. Learn
  2. /
  3. Courses
  4. /
  5. Monte Carlo Simulations in Python

Exercise

Paired dice simulation

Similar to the example in the lesson, you will roll two dice from two bags, and each bag contains three biased dice.

bag1 = [[1, 2, 3, 6, 6, 6], [1, 2, 3, 4, 4, 6], [1, 2, 3, 3, 3, 5]]
bag2 = [[2, 2, 3, 4, 5, 6], [3, 3, 3, 4, 4, 5], [1, 1, 2, 4, 5, 5]]

The difference is that the dice in the two bags are paired: if you pick the second die in bag1, you will also pick the second die in bag2. In each trial:

  • You pick one pair of dice from the two bags randomly and roll them
  • Success occurs if the points on dice1 and dice2 add up to eight; otherwise, failure

Your task is to complete the for-loop in the roll_paired_biased_dice() function and to use this function to calculate the probabilities of success for each unique combination of points on dice1 and dice2.

The following have been imported for you: random, numpy as np, pandas as pd, seaborn as sns and matplotlib.pyplot as plt.

Instructions 1/2

undefined XP
    1
    2
  • Use random.randint() to obtain the dice indices (each a number from 0 to 5).
  • Use bag_index followed by the correct dice_index to sample a pair of dice from bag1 and bag2.