Workshop · Python · Kids
PY010 Python for kids: the Story Machine
Pixel the robot wants to tell stories, and the only way to teach Pixel is Python. In six short sits a child prints robot faces, makes Pixel remember words and numbers, counts down a rocket, rolls dice against Captain Mango, teaches Pixel tricks, and finally builds the Story Machine. Every step is a tiny program the child runs themselves, and the machine checks it by trying it with a new word and a new number.
Open Coding Tutor at codingtutor.agilesystemsoftware.com, pick PY010 from the course button in the chat and press Tutor me. Every lesson, demo and hands-on step is also published below.
Who it is for
Children of about 8 to 12 with a guardian or teacher nearby who sets up the seat and sits in on the first session. No typing speed needed, no maths beyond counting. Everything is a picture, a countdown, a dice game or a story told by Pixel the robot and Captain Mango.
A kids course: a guardian or teacher sets up the seat and stays nearby. The tutor never asks for personal details, answers come through buttons or by voice, and nothing is shared or ranked. How kids courses work.
What you will be able to do
- Run a Python file and change what it prints
- Keep a word or a number in a named box and use it in a sentence
- Repeat something a chosen number of times with a for loop
- Let the program choose with if and else, and roll dice
- Teach the computer a trick with def and use it again and again
- Pick things from a list to build a story
Syllabus
Every session ends in a lab the machine checks on your own code. Open a session's mini steps to read each lesson, demo and hands-on task; the badge shows how far the engine can verify it: checked · T3 a check runs over your files, proven · T4 the grader also tries inputs you did not see, tutored · T0 done on your word. Each step has its own link (for example #s1-1).
- 1. Hello, Pixel
- 2. Pixel remembers
- 3. Again and again
- 4. Pixel chooses
- 5. Teach Pixel a trick
- 6. The Story Machine show
Session 1 · Hello, Pixel
Four tiny steps with a grown-up nearby. Pixel the robot lives in a file and wakes up when you run it. Change the words and Pixel says something new. Draw Pixel's face out of letters and symbols. Give Pixel a magic word after the file name and watch it use it. Live in the seat: the tutor runs pixel.py, changes one word, draws a face, and shows the magic word trick.
Lab Make Pixel's sign: a program that draws a picture of Pixel and says hello to whatever word comes after the file name. The machine will try it with a word you did not pick. Session 1 checkpoint.
4 mini steps · ~23 min
1.1Wake up, Pixel5 minchecked · T3
Predict
The file says print("Beep! I am Pixel."). When you run it, what shows up?
Lesson
A program is words in a file. When you run the file, the computer reads it line by line and does what it says. print means "show this on the screen". Change the words, run again, and Pixel says something new.
Demo
The tutor opens python/py010/demo/pixel_demo.py, clicks in the terminal, types python3 demo/pixel_demo.py, and Pixel says Beep. The tutor changes Beep to Boop, runs again, and both lines sit in the terminal.
Hands-on
Open python/py010/s1/pixel.py. It says Beep. Change the words so Pixel says something funny, then run it with python3 s1/pixel.py. Add a second print line so Pixel says two things.
Explain
Say it out loud: what does print do?
Check
pixel.py says two new things — checked (T3):
seat_run1.2Pixel's face6 minchecked · T3
Predict
You want Pixel to have eyes on one line and a mouth on the next. How many print lines do you need?
Lesson
Every print makes one line. Put symbols like [ ] o _ and = inside the quotes and you can draw with them. A face is just a few prints stacked on top of each other.
Demo
The tutor draws a four-line robot face in python/py010/demo/face_demo.py — a hat line, an eyes line [o o], a nose, a mouth line — runs it, then changes one eye to x and runs again so Pixel winks.
Hands-on
In python/py010/s1/face.py draw Pixel's face with at least four print lines. Use [ and ] for the head and o for the eyes. Run it. Then make Pixel wink by changing one eye.
Explain
How did you make the face taller?
Check
face.py draws at least four lines with eyes — checked (T3):
seat_run1.3The magic word6 minproven · T4
Predict
You run python3 s1/magic.py Mango. Inside, word = sys.argv[1]. What is in word?
Lesson
You can give a program a magic word when you run it: type it after the file name. Two lines catch it — import sys and word = sys.argv[1]. Now word is a box holding whatever you typed, and Pixel can say it.
Demo
The tutor writes python/py010/demo/magic_demo.py with the two catching lines and print("Pixel likes", word), runs it with Mango, then with Pancakes, and Pixel says each one.
Hands-on
Write python/py010/s1/magic.py: import sys, word = sys.argv[1], then print Pixel saying the word, like "Pixel shouts: Mango!". Run it with three different words. Never use a real person's name; make one up.
Explain
Where does the magic word come from?
Check
magic.py says the word it was given — proven (T4):
seat_run1.4Lab: Pixel's sign6 minproven · T4
Predict
Your sign prints a face and then "Hello, Mango!". Where does Mango come from?
Lesson
Put the two things together: a face made of print lines, and a hello line that uses the magic word. That is Pixel's sign, and it works for any word anyone gives it.
Demo
The tutor builds python/py010/demo/sign_demo.py: the face from 1.2 on top, then print("Hello,", word + "!") underneath; runs it with Mango and with Rocket.
Hands-on
Write python/py010/s1/sign.py: at least four face lines, then a line that says "Hello, <word>!" using the magic word. Run python3 s1/sign.py Mango and the last line must be exactly Hello, Mango!
Explain
Tell the tutor: what will your sign say if the word is Banana?
Check
Pixel's sign greets any word — proven (T4):
seat_run
Session 2 · Pixel remembers
Four steps about boxes with names. A variable is a box: put a word or a number in it and use the name later. Numbers can be added and multiplied; words cannot, and Python tells you so. An f-string lets you drop a box into the middle of a sentence. Live in the seat: a box filled and refilled, 3 + 4 next to "3" + "4", and Pixel saying a sentence with two boxes inside it.
Lab Make the counting robot: it takes a made-up name and a number of cookies, and prints how many there are now, tomorrow (one more) and doubled. The machine tries other names and numbers. Session 2 checkpoint.
4 mini steps · ~23 min
2.1A box with a name5 minchecked · T3
Predict
pet = "cat" then pet = "dog" then print(pet). What shows?
Lesson
A variable is a box with a name. pet = "cat" puts cat in the box called pet. Use the name anywhere and Python looks in the box. Put something new in and the old thing is gone.
Demo
In python/py010/demo/box_demo.py the tutor makes a box called snack, prints it, changes what is inside, prints it again, then prints the box name in quotes to show the difference between the name and the thing inside.
Hands-on
Write python/py010/s2/box.py: make a box called robot holding "Pixel" and a box called food holding "bolts". Print "Pixel eats bolts" using the two boxes with print(robot, "eats", food). Then change food and run again.
Explain
What happens to the old thing when you put something new in a box?
Check
box.py uses two boxes in one line — checked (T3):
seat_fileseat_run2.2Numbers that count6 minproven · T4
Predict
cookies = 3; print(cookies + 1, cookies * 2). What shows?
Lesson
Numbers do not need quotes. + adds, - takes away, * multiplies. A magic word is always a word, so to count with it you turn it into a number with int(): cookies = int(sys.argv[1]).
Demo
The tutor shows 3 + 4 and "3" + "4" in python/py010/demo/count_demo.py — 7 and 34 — then catches a magic number with int(sys.argv[1]) and prints it plus one and times two.
Hands-on
Write python/py010/s2/count.py: catch a magic number with int(sys.argv[1]) into a box called cookies; print cookies + 1 and cookies * 2 on two lines. Run it with 3, then with 10.
Explain
Why do we need int() around the magic word?
Check
count.py adds one and doubles the magic number — proven (T4):
seat_run2.3Words and numbers in one sentence6 minproven · T4
Predict
name = "Mango"; n = 2; print(f"{name} has {n} hats"). What shows?
Lesson
An f-string is a sentence with holes. Put f before the quote and {box} where you want the box's contents. Python fills the holes when it prints. Words and numbers both fit.
Demo
In python/py010/demo/fstring_demo.py the tutor writes f"{robot} found {n} bolts", runs it, forgets the f to show the holes staying empty, then puts it back.
Hands-on
Write python/py010/s2/sentence.py: catch a magic word into name and a magic number into n (with int). Print f"{name} has {n} cookies." and f"Tomorrow {name} has {n + 1}." Run it with Mango 3.
Explain
What does the f do before the quote?
Check
sentence.py fills two sentences from the magic words — proven (T4):
seat_fileseat_run2.4Lab: the counting robot6 minproven · T4
Predict
The counting robot gets Mango 5. What is the doubled line?
Lesson
The counting robot catches a made-up name and a number, then tells three things: how many cookies now, how many tomorrow (one more), and how many if they doubled. Three boxes, three f-strings.
Demo
The tutor builds python/py010/demo/robot_demo.py step by step — catch, catch with int, three prints — and runs it with Mango 5 and Zed 1.
Hands-on
Write python/py010/s2/robot.py. python3 s2/robot.py Mango 5 must print exactly: "Mango has 5 cookies." then "Tomorrow: 6" then "Double: 10".
Explain
Which line would change if the number were 100?
Check
The counting robot counts for any name and number — proven (T4):
seat_run
Session 3 · Again and again
Four steps about repeating. A for loop does its indented lines once for every number in range. Patterns grow when the loop number changes what gets printed. A countdown runs the numbers backwards. Live in the seat: Pixel saying hello five times from one print, a staircase of stars, a 3-2-1 countdown, and the rocket that launches at the end.
Lab Make the rocket launch: count down from the magic number to 1, print "Blast off!", then draw the rocket. The machine tries other starting numbers. Session 3 checkpoint.
4 mini steps · ~23 min
3.1Say it again, Pixel5 minproven · T4
Predict
for i in range(3): print("Beep"). How many Beeps?
Lesson
for i in range(n): means do the indented lines n times. The lines that are pushed in (indented) belong to the loop. One print inside a loop can fill the whole screen.
Demo
The tutor writes a loop in python/py010/demo/again_demo.py that prints Beep three times, changes 3 to 10, then un-indents the print to show it running only once.
Hands-on
Write python/py010/s3/again.py: catch a magic number n with int, then a for loop that prints "Pixel says hi!" n times. Run it with 4.
Explain
How does Python know which line to repeat?
Check
again.py repeats n times — proven (T4):
seat_fileseat_run3.2Star patterns6 minproven · T4
Predict
print("*" * 3) shows?
Lesson
"*" * 3 makes "***". Inside a loop, the loop number i changes each turn, so print("*" * i) draws a staircase: one star, then two, then three. Patterns come from the number changing.
Demo
In python/py010/demo/stars_demo.py the tutor prints "*" * 5, then a staircase with range(1, 6), then swaps * for = to make a flag.
Hands-on
Write python/py010/s3/stairs.py: catch a magic number n; for i in range(1, n + 1) print "*" * i. Run with 4 and see four steps.
Explain
Why does each line have one more star?
Check
stairs.py draws n steps — proven (T4):
seat_run3.3Countdown6 minproven · T4
Predict
for i in range(3, 0, -1): print(i). What is the first line?
Lesson
range can count backwards: range(start, 0, -1) goes from start down to 1. That is a countdown. After the loop ends, the next un-indented line runs once — perfect for "Blast off!".
Demo
The tutor writes python/py010/demo/countdown_demo.py counting down from 5 with a print("Blast off!") after the loop, runs it, then indents Blast off by mistake to show it shouting five times.
Hands-on
Write python/py010/s3/countdown.py: catch a magic number n; count down from n to 1, one number per line; then print "Blast off!" once. Run with 3.
Explain
Why is Blast off not indented?
Check
countdown.py counts down then blasts off once — proven (T4):
seat_run3.4Lab: the rocket launch6 minproven · T4
Predict
The rocket counts down from 4. How many lines come before "Blast off!"?
Lesson
The rocket launch is the countdown plus a picture: count down from the magic number, print "Blast off!", then draw a rocket with print lines. A loop and a picture in one program.
Demo
The tutor builds python/py010/demo/rocket_demo.py: the countdown loop, Blast off, then a four-line rocket (a tip ^, a body | |, a base /__\, flames). Runs it with 3 and with 6.
Hands-on
Write python/py010/s3/rocket.py: countdown from the magic number to 1, then "Blast off!", then a rocket of at least four lines whose first line is " ^ ". Run with 4.
Explain
What changes when the magic number is bigger?
Check
The rocket launches from any number — proven (T4):
seat_run
Session 4 · Pixel chooses
Four steps about choosing. if asks a yes-or-no question and runs its lines only when the answer is yes; else is what happens otherwise. Dice: random.randint rolls a number, and a seed makes the same roll happen again so the machine can check. elif adds more questions. Live in the seat: a number called big or small, a die rolled with the same seed twice, a mood ladder, and Pixel versus Captain Mango at dice.
Lab Make the dice duel: with a seed from the magic number, roll a die for Pixel and one for Captain Mango, print both rolls and who won. The machine tries other seeds. Session 4 checkpoint.
4 mini steps · ~23 min
4.1Big or small?5 minproven · T4
Predict
n = 7. if n > 5: print("big") else: print("small"). What shows?
Lesson
if n > 5: asks "is n more than 5?" If yes, the indented lines under if run. If no, the lines under else run. Only one of the two happens.
Demo
The tutor writes python/py010/demo/bigsmall_demo.py, runs it with 7 and 2, then changes > to < and runs again to show the answers swapping.
Hands-on
Write python/py010/s4/bigsmall.py: catch a magic number n; if n > 5 print "big", else print "small". Run with 7, then with 2.
Explain
How many of the two lines print each time?
Check
bigsmall.py chooses big or small — proven (T4):
seat_fileseat_run4.2Rolling a die6 minproven · T4
Predict
random.randint(1, 6) can give which numbers?
Lesson
import random, then random.randint(1, 6) rolls a die. random.seed(number) makes the dice "remember" a roll: the same seed always gives the same rolls, which is how the machine can check your game.
Demo
In python/py010/demo/dice_demo.py the tutor rolls three times, runs twice and gets different numbers, adds random.seed(7), runs twice and gets the same numbers.
Hands-on
Write python/py010/s4/dice.py: catch a magic number and use it as random.seed; roll a die with randint(1, 6) and print "You rolled N". Run it twice with 7 and see the same roll.
Explain
Why do we give the dice a seed?
Check
dice.py rolls 1 to 6 with a seed — proven (T4):
seat_fileseat_run4.3Pixel's moods6 minproven · T4
Predict
n = 5: if n > 8 "happy", elif n > 3 "okay", else "sleepy". What shows?
Lesson
elif means "or else, if". You can stack questions: Python tries them from the top and runs the first one that is yes. Everything after is skipped. else catches the rest.
Demo
The tutor writes a mood ladder in python/py010/demo/mood_demo.py for Pixel's battery level, runs 9, 5 and 1, then swaps two rungs to show the order mattering.
Hands-on
Write python/py010/s4/mood.py: catch a battery number; print "Pixel is happy" if more than 8, "Pixel is okay" if more than 3, else "Pixel is sleepy". Try 9, 5 and 1.
Explain
What does Python do after it finds a yes?
Check
mood.py picks one mood — proven (T4):
seat_fileseat_run4.4Lab: the dice duel6 minproven · T4
Predict
Pixel rolls 4 and Captain Mango rolls 4. What should the last line say?
Lesson
The duel: seed the dice with the magic number, roll once for Pixel and once for Captain Mango, print both rolls, then use if / elif / else to say who won or if it is a tie.
Demo
The tutor builds python/py010/demo/duel_demo.py — seed, two rolls, two prints, the three-way choice — runs it with 7 and with 3, and points at the tie branch when it happens.
Hands-on
Write python/py010/s4/duel.py. python3 s4/duel.py 7 prints "Pixel rolls N", "Mango rolls N", then "Pixel wins!", "Mango wins!" or "Tie!". Try several seeds until you see all three endings.
Explain
Why does the duel need three choices, not two?
Check
The dice duel rolls, compares and names a winner or a tie — proven (T4):
seat_fileseat_run
Session 5 · Teach Pixel a trick
Four steps about tricks. def gives a name to a few lines so you can use them again by saying the name. A trick can take things in (a word, a number) and can give something back with return. Live in the seat: a wave() trick used three times, a trick that takes a name, a trick that gives back a doubled number, and the text pet Biscuit who eats and plays.
Lab Make the text pet: tricks called feed and play that print what the pet does, and a trick called happiness that gives back a number. The machine tries other pet names and amounts. Session 5 checkpoint.
4 mini steps · ~23 min
5.1A trick with a name5 minchecked · T3
Predict
You write def wave(): print("o/") and then wave() twice. How many o/ appear?
Lesson
def wave(): followed by indented lines teaches Pixel a trick called wave. Nothing happens until you call it with wave(). Call it as many times as you like — the lines run each time.
Demo
In python/py010/demo/trick_demo.py the tutor defines wave() with two print lines, runs the file to show nothing happens, then adds three calls and sees three waves.
Hands-on
Write python/py010/s5/wave.py: a trick wave() that prints "o/" and "Hi there!"; call it exactly three times. Run it: six lines.
Explain
Why did nothing print before you called wave()?
Check
wave.py defines wave and calls it three times — checked (T3):
seat_fileseat_run5.2Tricks that take things in6 minproven · T4
Predict
def greet(who): print(f"Hi {who}!") then greet("Mango"). What shows?
Lesson
A trick can take things in: def greet(who): makes a box called who that is filled each time you call greet("Mango"). Two boxes work too: def cheer(who, times): and a loop inside.
Demo
The tutor writes greet(who) and cheer(who, times) in python/py010/demo/takein_demo.py and calls them with different words and numbers.
Hands-on
Write python/py010/s5/cheer.py: a trick cheer(who, times) that prints f"Go {who}!" times times using a loop. Catch a magic word and number and call cheer with them. Run with Mango 3.
Explain
What is who while the trick runs?
Check
cheer.py cheers a name a number of times — proven (T4):
seat_fileseat_run5.3Tricks that give something back6 minproven · T4
Predict
def double(n): return n * 2 then print(double(4)). What shows?
Lesson
return makes a trick hand an answer back instead of printing it. Then you can print the answer, or use it in another sum. A trick with return is like a calculator button.
Demo
In python/py010/demo/giveback_demo.py the tutor writes double(n) with return, prints double(4), then double(double(4)), then shows a version with print instead of return giving None.
Hands-on
Write python/py010/s5/double.py: a trick double(n) that returns n * 2 and a trick add_one(n) that returns n + 1. Catch a magic number and print double(n) then add_one(double(n)). Run with 5: lines 10 and 11.
Explain
What is the difference between return and print?
Check
double.py returns doubled and plus-one values — proven (T4):
seat_fileseat_run5.4Lab: the text pet6 minproven · T4
Predict
happiness(fish) returns fish * 10. Biscuit eats 3 fish. What is the happiness line?
Lesson
The text pet has three tricks: feed(name, fish) prints what it eats, play(name) prints what it plays with, and happiness(fish) gives back fish times 10. The main part catches a pet name and a number and uses all three.
Demo
The tutor builds python/py010/demo/pet_demo.py trick by trick, calling each one as it is written, and runs it with Biscuit 3 and Waffle 1.
Hands-on
Write python/py010/s5/pet.py. python3 s5/pet.py Biscuit 3 prints exactly: "Biscuit eats 3 fish.", "Biscuit plays with a ball.", "Happiness: 30". The pet's name is made up, never a real person's.
Explain
Which trick gives something back, and why that one?
Check
The text pet eats, plays and reports happiness for any name and number — proven (T4):
seat_fileseat_run
Session 6 · The Story Machine show
Four steps that build the show. A list is a row of things in square brackets; you can pick one by number. random.choice picks one for you, and with a seed the same picks come back so the machine can check. A sentence built from three lists is a story; a loop makes several. Live in the seat: a list of heroes, a seeded random pick, one story sentence, and the finished Story Machine printing a whole tale about the hero you named.
Lab Build the Story Machine: it takes a hero name and a number of lines, seeds the dice, and prints that many story lines made from lists of places, friends and things to do. The machine tries other heroes and lengths. Course completion step.
4 mini steps · ~23 min
6.1A row of things5 minchecked · T3
Predict
places = ["moon", "cave", "sea"]; print(places[0]). What shows?
Lesson
A list is a row of things inside square brackets, separated by commas. Pick one by its number in square brackets — and the first number is 0, not 1. len(places) tells you how many there are.
Demo
The tutor makes a list of three places in python/py010/demo/list_demo.py, prints places[0], places[2], len(places), then tries places[3] to show the error for a seat that is not there.
Hands-on
Write python/py010/s6/places.py: a list of four made-up places; print the first one, the last one, and how many there are — three lines.
Explain
What number picks the first thing in a list?
Check
places.py makes a list of four and prints first, last, count — checked (T3):
seat_fileseat_run6.2Let the dice pick6 minproven · T4
Predict
random.choice(["moon", "cave"]) can give?
Lesson
random.choice(list) picks one thing from a list. With random.seed(number) first, the same picks come back every run, so the machine can check your show and you can replay a story you liked.
Demo
In python/py010/demo/pick_demo.py the tutor seeds with the magic number, picks a place three times, runs twice to show the same picks, then changes the seed.
Hands-on
Write python/py010/s6/pick.py: catch a magic number for the seed; make a list of three friends; print "Pixel meets <friend>" twice using random.choice. Run with 7 twice and see the same friends.
Explain
Why does the same seed give the same story?
Check
pick.py seeds and picks twice — proven (T4):
seat_fileseat_run6.3One story line6 minproven · T4
Predict
A story line is f"{hero} went to the {place} with {friend}." How many lists does it pick from?
Lesson
One story line is an f-string with three holes: the hero, a place picked from a list, a friend picked from a list. Put it in a trick called story_line(hero) that returns the sentence, and you can make as many as you like.
Demo
The tutor writes story_line(hero) in python/py010/demo/line_demo.py with two picks and one f-string, prints it three times, and reads the three different sentences aloud in a storyteller voice.
Hands-on
Write python/py010/s6/line.py: lists of places and friends; a trick story_line(hero) that returns f"{hero} went to the {place} with {friend}."; catch a hero name and a seed; print story_line(hero) once.
Explain
Why put the sentence in a trick?
Check
line.py returns one story line about the hero — proven (T4):
seat_fileseat_run6.4Lab: the Story Machine6 minproven · T4
Predict
The Story Machine gets Mango 4 7. What is the 4?
Lesson
The Story Machine: catch a hero, a number of lines and a seed; seed the dice; print a title line "The tale of <hero>"; then a loop that prints story_line(hero) that many times; then "The end.". Everything from the course in one show.
Demo
The tutor builds python/py010/demo/story_demo.py from line_demo.py — title, loop, The end — runs it with Mango 4 7, then with Biscuit 2 1, and asks the child what they would add.
Hands-on
Write python/py010/s6/story.py. python3 s6/story.py Mango 4 7 prints "The tale of Mango", then four story lines about Mango, then "The end." — six lines. Show a grown-up your show.
Explain
Tell the tutor your favourite line and what list it came from.
Check
The Story Machine tells a tale of any length about any hero — proven (T4):
seat_fileseat_run
Outcome
By the end of the course the tutor's checks will have verified: twenty-four small programs the child ran themselves; six playful labs — Pixel's sign, the counting robot, the rocket launch, the dice duel, the text pet and the Story Machine — each checked by the machine with words and numbers the child did not pick.
Completion
No certificate for kids courses. When the last show is done, the guardian or teacher receives a completion card listing the sessions and the checks the machine ran. No streaks, no leaderboards, nothing shared.
Environment
A VS Code seat in the browser, set up by a guardian or teacher, with Python 3.13 ready and offline; one file per program, run with python3. Your work lives in python/py010; the tutor's demo files live apart from yours and the tutor never edits your hands-on file while you are working on it.
Open Coding Tutor at codingtutor.agilesystemsoftware.com, pick PY010 from the course button in the chat and press Tutor me. Every lesson, demo and hands-on step is also published below.