die 2?die 1?1234561234562343546574657685768796879810798109111011121len(S)2P(A)31 - P(A)4P(B)5P(A.union(B))6randint(1, 6)
Dice: die 1 picks the row, die 2 the columnBoard: the sample space, 36 equally likely outcomes, each showing its sumFilled squares: the event in focus; ringed squares: a second eventCalculator and Python card: count, then divide by 36Every square of the 6 × 6 board is one outcome of rolling two dice: die 1 picks the row, die 2 the column, and the square shows the sum. An event is a set of squares. With fair dice every square is equally likely, so P(event) = squares in it ÷ 36: a sum of 7 is 6/36 = 1/6, at least one six is 11/36, either one is 15/36. Order matters in this sample space: (1, 6) and (6, 1) are different outcomes, because the two dice are different objects. That is why there are 36 outcomes and not 21.

Outcomes and events

  1. Probability measures how likely something is. Start with an experiment: roll two fair dice. One result, like die 1 showing 3 and die 2 showing 4, is called an outcome. Write it as the pair (3, 4).

Counting chance

Combining events

In code

Try it in the Python prompt

;; step 1/10 · Roll two dice
>>> from fractions import Fraction
>>> from random import randint, seed
>>> D = range(1, 7)            # a die: 1 to 6
>>> (3, 4) == (4, 3)           # order matters: die 1 first
False

The Python lines in the steps build on each other: run them in order in one session, starting with the imports in step 1. Fraction keeps answers exact: Fraction(6, 36) prints as Fraction(1, 6). Floats round, so float(Fraction(1, 6)) prints 0.16666666666666666.