🪙

Coin flip streaks

Flip a coin 100 times — what's the longest streak of heads?

Builder· ages 10–1220 minrandomforcountingif
streaks.py

First load pulls ~10 MB of Python. Only happens once — the browser caches it after.

What should the output look like?

You should see the first 30 flips, counts of heads and tails, and a longest-streak line.

📖

How this works

This flips a coin many times and hunts for the longest run of the same side (like HHHHH). It uses two counters: one for the current streak, one for the best streak so far.

Your turn — try these

  • 1Change flips to 10,000. What's the longest streak now?
  • 2Run 100 sets of 100 flips. What's the average longest streak?
  • 3Flip a weighted coin (70% heads) — how does it change the streak?