🎲

Dice roller

Roll any number of six-sided dice and see the total.

Sprout· ages 8–1010 minimportrandomforcounters
dice.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 each roll and a grand total at the end.

📖

How this works

random.randint(1, 6) picks a number between 1 and 6 — like one roll of a die. A for loop does the same thing many times, and a total variable adds each roll up as we go.

Your turn — try these

  • 1Change the dice to 20-sided (1..20) instead of 6-sided.
  • 2Print "double!" when two dice in a row show the same number.
  • 3Print how many of your rolls were exactly 6.