Skip main navigation

Practise modifying code

Practise modifying code

The Python code we developed for comparing the values of two dice in the previous step can be modified to study a different kind of dice, called Grime Dice (invented by James Grime). Watch the video to find out more about the Grime dice.

We can investigate Grime dice by rolling them many times (in Python) and then doing some simple counting to analyse the data from the rolls.

Grime Dice are regular six-sided dice, but instead of the faces having labels 1,2,3,4,5,6 we’ve given them face labels as follows. The colours of the dice are just to be able to clearly tell them apart from each other.

  • The RED dice has its faces labelled [3,3,3,3,3,6]
  • The BLUE dice has its faces labelled [2,2,2,5,5,5]
  • The GREEN dice has its faces labelled [1,4,4,4,4,4]

The Python code we saw earlier, for comparing the values on two dice (win, loss, draw), has been modified to compare, for example, the RED dice playing against the BLUE dice. For these Grime Dice, there are never any draws because no two dice share a common face label. The NumPy library function np.random.choice randomly selects one of the values in the list of face labels provided. Each dice is rolled 60000 times.

myrollsA = np.random.choice([3,3,3,3,3,6], size=60000)
myrollsB = np.random.choice([2,2,2,5,5,5], size=60000)
mysum_win = np.sum(myrollsA > myrollsB)

Your task

Run the Python code above in your Jupyter Notebook to compare the RED dice with the BLUE dice. Which dice has the most wins from 60000 rolls, RED or BLUE?
Now, modify the code to compare the BLUE dice with the GREEN dice. Which dice has the most wins from 60000 rolls, BLUE or GREEN?
If you now compared the RED dice with the GREEN dice, which do you think would have the most wins from 60000 rolls? Modify the code again to check your hypothesis.
Share your answers to each question and your modified code with your fellow learners in the discussion area. What did you learn from this? Did your modifications work first time? Did your hypothesis prove true?


Grime, J. (n.d.). Non-transitive dice.

Grime, J. (2010, August 5). Non-transitive dice. [Video] YouTube.

This article is from the free online

Get ready for a Masters in Data Science and AI

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now