Skip to content
DoingCamp CS

Make it comfy

Lesson style

Quick mode shows the key picture, a summary and the practice. Good for a refresher.

Theme
Font

Both fonts are designed to be easy to read. Some readers with dyslexia prefer Lexend.

Text size
Spacing
Animations

Lesson 1 of 20 · about 14 min

Chance and frequency

What does "a 1 in 6 chance" actually mean? You'll flip coins and roll dice thousands of times in a second, watch the results settle towards a fixed number, and learn the words every probability question is built from. Then you'll find the mistake that fooled a famous mathematician.

🧭 What you need first: Permutations and combinations

The story

A board game says you need a six to start. Your friend rolls six times and gets no six at all. “This die is broken,” she says. “One in six means one six every six rolls!”

Is she right? Not quite, and figuring out why is what this course is about. “1 in 6” doesn’t promise one six in every six rolls. It promises something subtler: in the long run, about one roll in six will be a six. In any short run, anything can happen. (No six in six rolls happens about a third of the time. You’ll be able to prove that in lesson 4.)

Probability is the math of things you can’t predict one at a time but can predict in bulk. It runs spam filters, weather forecasts, video-game loot drops, medical tests, and the random choices inside fast algorithms. And it’s famously easy to get wrong, even for experts. So we’ll do something research on learning says works well: predict first, then test your prediction with a simulation, then learn the rule that explains what you saw.

Another way: a bag of marbles

A bag holds 1 red marble and 5 blue ones. Reach in without looking: you can’t say which color you’ll get. But if you draw (and put back) 600 times, you’d bet on getting red about 100 times. Probability is that “about 100 out of 600” kind of knowledge.

Play with it

Flip it a thousand times

First, make a prediction. No peeking at the answers by trying it first!

You flip a fair coin 10 times. Will you get exactly 5 heads?

Now try it. Press Flip ×10 a few times (with ↺ Reset in between) and see how often you get exactly 5 heads. Then keep going to 1,000 flips and watch the purple line in the second chart.

🎯 1/2: Flip the coin 10 times. Did you get exactly 5 heads?

Press a button to flip a fair coin that many times. Watch the share of heads in the second chart.

Nothing yet: flip to start.

0 flips so far · heads: 0

HeadsTails

How often each outcome came up (purple = counts as heads).

0%50%100%probability 50%11 flips

Purple line: share of heads so far. Green dashed line: the probability.

The purple line jumps around wildly at first, then settles down near the green 50% line. Now do the same for the die from the story: does the share of sixes settle near 1 in 6 (about 16.7%)?

🎯 1/1: Roll the die at least 3,000 times. Where does the share of sixes settle?

Press a button to roll a fair six-sided die that many times. Watch the share of sixes in the second chart.

Nothing yet: roll to start.

0 rolls so far · a six: 0

123456

How often each outcome came up (purple = counts as a six).

0%50%100%probability 16.7%11 rolls

Purple line: share of sixes so far. Green dashed line: the probability.

Name it

The real words

  • An experiment is anything with an uncertain result: flipping a coin, rolling a die, sending a network packet that might get lost.

  • An outcome is one possible result. The Sample space is the set of all outcomes, often written SS:

    • one coin: S={H,T}S = \{H, T\}
    • one die: S={1,2,3,4,5,6}S = \{1, 2, 3, 4, 5, 6\}
  • An event is a set of outcomes (a subset of SS, like the sets in F06 lesson 1). “Roll an even number” is the event E={2,4,6}E = \{2, 4, 6\}. We say the event happens if the outcome lands inside it.

  • Probability P(E)P(E) is a number from 0 to 1. P=0P = 0 means it never happens; P=1P = 1 means it always does. When all outcomes are equally likely, you count:

    P(E)=∣E∣∣S∣P(E) = \frac{|E|}{|S|}

    so P(even)=36=12P(\text{even}) = \frac{3}{6} = \frac{1}{2}. (Recall ∣E∣|E| means “how many things are in EE”.)

  • The frequency view: if you repeat the experiment nn times, the share of times EE happens gets closer and closer to P(E)P(E) as nn grows. That’s what you watched the purple line do. Lesson 15 proves it (the law of large numbers).

  • A common trap: the share settles, but the count doesn’t have to. After 100,000 flips you might have 50,200 heads: 200 more than half, a bigger gap than you’d usually see after 100 flips, yet the share (50.2%) is much closer to 50%. Luck doesn’t “even out”; it gets outweighed by the huge number of new flips.

Build it

Count it exactly

When outcomes are equally likely, probability is just counting. Python’s Fraction keeps answers exact (1/6 stays 1/6, instead of 0.16666…).

Write prob(event, space): the probability of an event when every outcome in space is equally likely. Both are Python sets. Return a Fraction: the number of outcomes in the event that are also in the space, divided by the size of the space.

Challenge

The famous mistake

Roll two dice and add them. The sums go from 2 to 12: eleven possible sums. So is P(sum=7)=111P(\text{sum} = 7) = \frac{1}{11}?

No! The 11 sums are not equally likely, so you can’t just count them. The great 18th-century mathematician Jean d’Alembert made a mistake like this. Asked for the chance of at least one head in two coin flips, he listed three cases (heads at once; tails then heads; tails twice), treated them as equally likely and answered 2/3. But “heads at once” covers two equally likely outcomes, HH and HT, so the true answer is 3/4. The fix is to list outcomes that are equally likely: (first die, second die) pairs. That’s 6 × 6 = 36 of them (the product rule, F06 lesson 5).

Build the sample space of two dice as a list of all 36 pairs (a, b). Then write p_sum(s): the exact probability (a Fraction) that the two dice add up to s. Finally, simulate(trials) rolls two random dice trials times and returns the share of rolls that summed to 7.

7 is the most common sum because it has the most ways to happen: 1+6, 2+5, 3+4, 4+3, 5+2, 6+1. That’s why board games like Settlers of Catan make 7 special.

Remember it

You flip a fair coin 100,000 times. Which is most likely true?

Got it?

Finish the lesson to color it in on your map and collect its concept cards.

Did this lesson click?