Stage 1 Β· IMPORT

Imports β€” grab your toolbox

Every Python game starts by bringing in tools. Today we'll bring in pygame (for graphics) and random (for surprises).

🧠 Quick Recap (30 seconds)

Before we dive in β€” can you remember from Lesson 0 (Big Picture)?

Q1. Every Python game is shaped like a rocket. What are the 4 big parts?

Import · Setup · Body · End. Every game ever made β€” yours included β€” fits this template.

Q2. How many stages will we build to make Galaxy Defender?

10 stages β€” just like the Rocket Ladder. Each stage adds one new idea on top of the last one.

Where we are on the rocket

Rocket Ladder infographic β€” Stage 1 highlighted by arrows. β–Ά β—€

You're on Stage 1 of 10.

What is an "import"?

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.

So what's 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.

The three libraries we'll meet in this course

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.

The recipe

Same idea as a baking recipe β€” short, ordered steps.

  1. Open your code editor below.
  2. Type import pygame on the first line.
  3. Type import random on the second line.
  4. Click Run. If nothing crashes, your boxes are open and ready. πŸŽ‰

Look at the Code Recipe handout β€” every lesson follows this same pattern.

The code so far

# Stage 1 β€” Imports
import pygame
import random

print("Toolbox loaded! Ready for Stage 2.")
Try it yourself

Type the code into this in-browser editor and press Run

Type the code above into the editor, then click β–Ά Run.

πŸ† Mini-challenge

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!

Handouts for this lesson

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.

← Previous Lesson 0 Β· Big Picture