Every Python game starts by bringing in tools. Today we'll bring in pygame
(for graphics) and random (for surprises).
Before we dive in β can you remember from Lesson 0 (Big Picture)?
Import · Setup · Body · End. Every game ever made β yours included β fits this template.
10 stages β just like the Rocket Ladder. Each stage adds one new idea on top of the last one.
βΆ
β
You're on Stage 1 of 10.
When you write import something, you're telling Python:
"Go grab that toolbox and bring it here so I can use it."
The "toolbox" is called a library.
A library is simply a collection of pre-written code that someone else has already created to solve common problems. Instead of writing everything from scratch, you reuse those tools.
Think of Python itself as a basic toolbox β it knows how to add, print, compare, and loop. Libraries add extra toolboxes for specific jobs: one for graphics, one for sound, one for math, one for surprises.
π Another way to picture it: imagine you're building a house. Without libraries, you'd
make every brick yourself. With libraries, someone has already baked the bricks β you just
stack them. That's why one line (import pygame) can give you
thousands of ready-made tools.
import pygame
import turtle
import random
The big idea: one line of import unlocks an
entire toolbox of pre-written code. You write a small amount of code, and the library does
the heavy lifting behind the scenes.
Same idea as a baking recipe β short, ordered steps.
import pygame on the first line.import random on the second line.Look at the Code Recipe handout β every lesson follows this same pattern.
# Stage 1 β Imports
import pygame
import random
print("Toolbox loaded! Ready for Stage 2.")
Type the code above into the editor, then click βΆ Run.
Can you guess what would happen if you forgot to import random?
Try deleting that line, then try to use random.randint(1, 10).
Python will give you an error. Read it carefully β errors are clues, not scary!
Print these, keep them open in another tab, or download them to your computer.
π Code Library β ten tiny example programs you can copy straight into the Trinket editor above. Each one shows what a library can do.
π Code Library (10 mini programs)
πΊοΈ The big-picture handouts β keep these by your side for the whole course.
π Big Picture π Galaxy Map π Rocket Ladder π Code Recipe πΌοΈ 6 Parts of a Turtle Program
π€ Want to try your own idea? Ask an AI like Claude or ChatGPT something like "Write me a short Python turtle program that draws a flower", then paste the code into the Trinket editor above and click Run. Reading other people's code is one of the fastest ways to get better.