Lesson 23 of 30

Lesson 23 ? Dice adventure

Title: Make a tiny adventure with dice rolls

Description: Use random numbers and choices to create a small adventure story.

Why it matters for kids: Adventure programs combine random events, conditions, and text.


1. Roll a die

pythonpython
import random

roll = random.randint(1, 6)
print("You rolled:", roll)

2. Win on a high roll

pythonpython
import random

roll = random.randint(1, 6)

if roll >= 4:
    print("You crossed the bridge!")
else:
    print("The bridge wobbled. Try again.")

3. Random path

pythonpython
import random

paths = ["forest", "cave", "river"]
path = random.choice(paths)

print(f"You walk into the {path}.")

4. Random treasure

pythonpython
import random

treasures = ["coin", "gem", "magic feather"]
found_treasure = random.choice(treasures)

print("You found:", found_treasure)

5. Easy examples

pythonpython
import random

health = 10
hit = random.randint(1, 3)
health = health - hit

print("Health left:", health)
pythonpython
import random

monster = random.choice(["slime", "bat", "goblin"])
print("A", monster, "appears!")
pythonpython
import random

if random.choice([True, False]):
    print("The door opens.")
else:
    print("The door is locked.")

6. Mini challenge

Click each example to open it.

Example 1

Roll one die.

Example 2

Print a win for roll 4 or more.

Example 3

Print try again for a low roll.

Example 4

Choose a random path.

Example 5

Choose a random treasure.

Example 6

Choose a random monster.

Example 7

Subtract random damage from health.

Example 8

Print the health left.

Example 9

Open a random door.

Example 10

Create one tiny adventure story.