Lesson 12 of 30

Lesson 12 ? Random surprises

Title: Let Python pick something for you

Description: Use random to choose numbers, snacks, animals, and simple game events.

Why it matters for kids: Random choices make games feel different each time.


1. Import random

pythonpython
import random

number = random.randint(1, 6)
print("Dice roll:", number)

randint(1, 6) picks a whole number from 1 to 6.


2. Random animal

pythonpython
import random

animals = ["cat", "dog", "fox", "owl"]
chosen_animal = random.choice(animals)

print("Today your animal friend is:", chosen_animal)

3. Random game points

pythonpython
import random

points = random.randint(10, 50)
print(f"You found {points} points!")

4. Magic lunch picker

pythonpython
import random

lunches = ["pizza", "soup", "sandwich", "rice"]

print("Lunch idea:", random.choice(lunches))

5. Easy examples

pythonpython
import random

coin = random.choice(["heads", "tails"])
print("Coin:", coin)
pythonpython
import random

colors = ["red", "blue", "green"]
print("Robot color:", random.choice(colors))
pythonpython
import random

steps = random.randint(1, 5)

for step in range(steps):
    print("Hop!")

6. Mini challenge

Click each example to open it.

Example 1

Roll a random number from 1 to 6.

Example 2

Pick a random color from a list.

Example 3

Pick a random animal from a list.

Example 4

Pick a random snack from a list.

Example 5

Pick random points from 10 to 20.

Example 6

Flip a random coin.

Example 7

Choose a random robot name.

Example 8

Choose a random lunch.

Example 9

Print Hop! a random number of times.

Example 10

Create a random superhero name.