Suppose you flip a fair coin 5 times, and every single flip comes up Heads: H-H-H-H-H.
What would you bet on for the 6th flip? Most people feel a powerful, natural urge to bet on Tails, thinking: "Tails is due! Heads has come up too many times!"
This common psychological trap is known as the Gambler's Fallacy. In reality, a coin has no brain and no memory. It doesn't know what it landed on a moment ago!
In this lesson, we will simulate flipping a coin $50{,}000$ times. Every time we encounter a streak of 5 consecutive Heads, we'll examine what the 6th flip turned out to be. Are Tails really more likely after a streak? Let's find out!
if streak == target_streak then ... end
Move the mouse over a dotted box for more information.
Notice how the probability of getting Heads or Tails on the flip immediately following a 5-head streak remains stubbornly at $50/50$.
Now you try.
Try testing for streaks of 8 or 10 heads! You will see fewer total streaks in 50,000 flips, but the next flip will still be around 50% heads and 50% tails.
Type your code here:
See your results here:
To complete this lesson: We want to see whether Tails is more likely right after a streak of 5 Heads.
Look at the code above:
1. Near the top, target_streak is currently set to 0—change it to target_streak = 5.
2. In the else branch (when a coin lands on Tails), streak is currently reset to 99—change it to reset to streak = 0.
Then click Run to see if Tails is really "due"! Notice how the split stays right around 50/50. (If you get stuck, click Example above for the full working code).
Share your code
Show a friend, family member, or teacher what you've done!