Lesson 7.2: Story Randomizers

Today’s Goals

  • Use random.choice() to generate fun stories
  • Practice working with lists
  • Build creativity with Python

Warm-Up Question

  • If you could write a silly random story, what characters would you include?

Random Choice Basics

import random
animals = ["dragon", "unicorn", "robot"]
print(random.choice(animals))

Output: (one random item)

unicorn

Building a Random Story

import random
characters = ["wizard", "pirate", "alien"]
places = ["castle", "spaceship", "island"]
items = ["sword", "laser", "map"]

story = f"The {random.choice(characters)} found a {random.choice(items)} in the {random.choice(places)}."
print(story)

Class Practice

  • Add more options to the character, place, and item lists
  • Run your story generator multiple times

Student Challenge

  • Ask the user for their name and include it in the story
  • Create at least 3 different categories (e.g., animals, foods, objects)

Wrap-Up

  • Story randomizers show how lists and random work together
  • Next time: We’ll create silly chatbots