Kids Coding

Project: Story Generator

Pick random words from lists and print a new story every run.

KidsIntermediateProject: Story Generator

A new story every run

Keep lists of names, places, and verbs. random.choice picks one from each. Join them into sentences.

Story generator

import random

names = ["Sam", "Riley", "Jun"]
places = ["the moon", "a bus", "the library"]
verbs = ["danced", "sneezed", "sang"]

who = random.choice(names)
where = random.choice(places)
did = random.choice(verbs)

print(who + " " + did + " on " + where + ".")
print("Nobody expected that.")

Swap the word lists and the same story machine tells a brand-new tale. That reuse is the real prize, not the story itself.

Grow it

Add a second sentence. Add a list of objects. Print a title.

Real life

A campfire story where someone picks random cards: who, where, what they did.

Shuffle three piles. Draw one from each. That is random.choice.

Campfire cards

import random
who = random.choice(["a fox", "a robot", "a pirate"])
where = random.choice(["the bus", "the moon", "the kitchen"])
print("Once", who, "got stuck on", where + ".")

Change one word. Run it. That is how this idea shows up outside the lesson.

Try it

Exercise 1: Pick a random animal from cat, owl, or frog and print Today's animal is plus that animal.

Show solution
import random
animal = random.choice(["cat", "owl", "frog"])
print("Today's animal is " + animal)

FAQ: Project: Story Generator

Common questions about this page.

What is StudyGrid Kids?

StudyGrid Kids is a free coding path for children: Basic, Intermediate, and Advanced. Lessons use Python in the browser. No account and no install.

Should I run project: story generator examples locally for better learning?

Yes. Use the browser editor on StudyGrid for a quick check, then Download the example and run it on your computer. Local runs show real errors and the real toolchain, which is one of the fastest ways to learn project: story generator in this Kids Coding Python lesson (Project: Story Generator).

Which kids level should we start with?

Start at Basic if the child has never written code. Choose Intermediate if they can print, use variables, and write a simple if. Choose Advanced if they already use loops and lists.

Do kids need an account or an app?

No. Kids pages are public. Code runs in the Try Python editor at /try. We do not ask children for a name or an email.

What language do kids learn?

Python, with a first HTML page in Intermediate and Advanced. After Advanced, the main Python tutorial is the next step.

Is the kids coding track free?

Yes. The Kids home, the three levels, and the Python editor on StudyGrid (studygrid.in) are free.