Prerequisite · Start Here

Python Foundations

Grades 5–9 Interactive lab No install required

Every Python program is built from the same handful of ideas: store a value, show it, decide with it, repeat with it, collect it, and reuse logic with it. Work through each station, read real Python code, predict what it does, and check your thinking instantly — before you ever touch Pygame or any other Python project on this site.

Before Station 1

Where Python Came From

You're about to learn a language that's older than most of your teachers' careers, still growing, and named after a comedy troupe — not a snake.

1989

Dutch programmer Guido van Rossum starts Python over the Christmas holidays as a personal project, looking for a hobby to keep him busy during his week off from work.

1991

Python 0.9.0 is released to the public. It already has functions, error handling, and the list type you'll learn in Station 6.

2000

Python 2.0 brings garbage collection and Unicode support, and starts building the huge library of free, reusable code Python is now famous for.

2008

Python 3.0 cleans up inconsistencies in the language on purpose, even though it means old Python 2 code won't run without changes. Python 3 is what you're learning today.

Today

Python runs NASA's data analysis, Instagram's servers, and most of the world's AI research. It's consistently ranked the most popular language for beginners and professionals.

Why "Python"?

Not the snake — Guido was reading scripts from the British comedy show Monty Python's Flying Circus while naming the project and wanted something "short, unique, and slightly mysterious."

A language with a motto

Python's guiding rules are called The Zen of Python — type import this into any Python interpreter to read all 19 lines. Rule one: "Beautiful is better than ugly." Rule two: "Readability counts."

Before Station 1

What Actually Happens When Python Runs?

Think of a Python program like a recipe card: a list of instructions the computer follows one line at a time, top to bottom, exactly as written — nothing happens until you tell it to, and nothing happens out of order. Some lines work silently in the background (like measuring an ingredient). Other lines produce something you can actually see (like plating the dish). Here's what that looks like in real code:

name = "Nova"
print("Hello,", name)
  • name — a variable: a labeled box holding a value
  • = — the assignment: "put this value in the box"
  • "Nova" — a string value: text, always in quotes
  • print(...) — a function call: "show this on screen"

Now watch it actually run, one line at a time:

Click Step to begin…

That's the whole rhythm of this lab: read a line, decide what it does, check your thinking. Every station below teaches one new kind of line to add to that recipe.

0% Lab progress0 of 0 checked
Map

The Python Ladder

You just watched two lines run. Every rung below is really just one more kind of line to add to that same recipe — nothing on this map is new territory, it's the same idea repeated with a new job. Don't try to memorize these yet; skim the one-line description, then let each station below teach the rung hands-on. Click a rung any time to jump straight to its station.

Station 1

Variables & print()

A variable is a labeled box that holds a value. = stores a value in the box; it does not mean "equals" the way it does in math. print() shows a value on the screen.

robot_name = "Byte"
battery = 87
print(robot_name, "is at", battery, "percent.")

What does this print?

Pick the line you think Python would print.

Now fix it the other way: what variable name is missing from the blank so this code prints Level 5?

____ = 5
print("Level", level)

Look at the second line to see what name is used there.

Station 2

Data Types

Every value in Python has a type. The four you'll use constantly: str (text, in quotes), int (whole numbers), float (decimal numbers), and bool (True or False). Tap the correct type for each value.

"level 5"
42
3.5
True
"42"
10 > 3

Notice that "42" is a string because of the quotes — Python treats it as text, not a number.

Station 3

Operators

Arithmetic operators do math: + - * / plus two Python specials — // (floor division, drops the remainder) and % (modulo, keeps only the remainder). Comparison operators (== != > < >= <=) ask a yes/no question and produce a bool.

What does print(17 // 5) output?

Floor division throws away the leftover and rounds down.

What does print(17 % 5) output?

17 divided by 5 is 3 remainder 2 — % gives you just the remainder.

What does print("3" + "4") output?

Both sides are strings, so + glues the text together instead of adding numbers.

Station 4

Conditionals: if / elif / else

A conditional lets a program make decisions. Python checks each condition in order and runs the first block that is True — then skips the rest.

score = 72
if score >= 90:
    print("A")
elif score >= 70:
    print("B")
else:
    print("Keep practicing")

What prints?

72 is not ≥ 90, but it is ≥ 70 — and Python stops at the first true branch.

Fill in the comparison so the code below prints Access granted when pin is exactly 1234:

pin = 1234
if pin ____ 1234:
    print("Access granted")

Remember: a single = stores a value; this needs the "is equal to" operator.

Station 5

Loops: for & while

A for loop repeats once per item in a sequence — range(n) counts from 0 up to (but not including) n. A while loop repeats as long as a condition stays True.

for i in range(4):
    print(i)

Not sure? Trace it one step at a time before you answer:

Click Step to begin…

What prints?

range(4) counts 0, 1, 2, 3 — four numbers, starting at zero.

Fill in the blank so this while loop prints 0 1 2 and then stops (it must not run forever):

count = 0
while count < 3:
    print(count)
    count = count + ____

Without changing count, the condition count < 3 would stay true forever — an infinite loop.

Station 6

Lists

A list holds many values in order, in square brackets. Items are numbered starting at 0. .append() adds an item to the end. len() counts how many items are in it.

pets = ["cat", "dog", "fish"]
pets.append("hamster")
print(pets[1])
print(len(pets))

What prints on the first line?

Counting starts at 0, so index 1 is the second item: "dog".

What prints on the second line — how many items are in pets after the .append()?

The list started with 3 items; .append("hamster") made it 4.

Station 7

Functions

A function is a reusable block of code. def defines it, the names inside the parentheses are parameters (placeholders), and return sends a value back out to whoever called it.

def double(x):
    return x * 2

print(double(5))
print(double(10))

What prints?

Each call passes a different x into the same function: 5×2=10, 10×2=20.

Complete the function so greet("Nova") returns "Hi, Nova!":

def greet(name):
    return ____

You can join strings with +, or use an f-string like f"Hi, {name}!".

Integration · Mini Challenge

Predict the Full Output

This program uses every rung of the ladder: a variable, a list, a loop, a conditional, and a function. Read it carefully, then type exactly what it prints — one line per print().

def status(hp):
    if hp > 0:
        return "alive"
    else:
        return "defeated"

team = [30, 0, 15]

for hp in team:
    print(hp, status(hp))

Stuck? Step through it first:

Click Step to begin…

The loop runs once per number in team, calling status() fresh each time.

Extension

Where Python Goes Next

Once these eight ideas feel automatic, the same building blocks power every Python project on this site — and beyond.

Games — Pygame

The exact input/update/render loop every game runs on, built from the loops and conditionals you just learned.

Start Pygame: The Game Loop →
Data & Automation

Lists and loops scale up to spreadsheets, files, and scripts that do repetitive tasks automatically.

Artificial Intelligence

Every AI model in this site's Computer Science module — from n-gram predictors to neural networks — is Python functions operating on lists of numbers.

Ready for real code in motion?

Pygame: The Game Loop uses these exact variables, conditionals, and loops to move a sprite around the screen, frame by frame.

Next Lesson: Pygame →