Build with Python · free foundation + advanced labs

Learn Python by seeing how your code works.

Write Python, press Run, and see what it draws. Fourteen free modules that start from zero, then ten advanced modules on data structures and solving problems.

24 modulesFree and paid modulesHands-on labs
from scimigo import canvas, rectangle, circle, text

canvas(600, 400)
eye_color = "green"
rectangle(200, 100, 200, 180, color="orange")
circle(260, 170, 15, color=eye_color)
circle(340, 170, 15, color=eye_color)
text(235, 60, "My Robot", size=28)
My Robot
Runs real Python in your browser. The first load is about 10 MB.

24 modules

Part 1 teaches Python from nothing: variables, decisions, loops, functions and data, up to a game you build yourself. Part 2 uses it on harder problems: the data structures and patterns behind efficient programs.

Part 1 · Learn Python from zero14 modules · free

1

Make a Picture — A robot, then a house from a written description

By the end you can read a line of drawing code and say what it draws and where, write a short program that draws a picture someone has described to you, and use an error message to find the line that is wrong.

You build: A robot, then a house from a written description

  • A program is a list of instructions
  • One instruction, taken apart
  • Where is (x, y)?
  • Numbers, and text in quotes
  • Arguments with names
  • When Python says no
FreeReading materialInteractive lab
2

Values and Variables — A sunset controlled by three variables; a receipt

By the end you can work out an expression by hand, say what value every name holds after each line of a short program, and draw a picture that is controlled by a few names at the top.

You build: A sunset controlled by three variables; a receipt

  • Python as a calculator
  • A name for a value
  • Names do not follow each other
  • Read, work out, store
  • Number or text?
  • Use print to look inside
FreeReading materialInteractive lab
3

Decisions — A signal lamp; a thermometer that labels itself

By the end you can say whether a comparison is True or False, say which lines of a program will run for a given value, and turn a rule written in words into code and test it at its edges.

You build: A signal lamp; a thermometer that labels itself

  • Questions with yes-or-no answers
  • One equals sign or two?
  • if, and the lines that belong to it
  • Otherwise
  • More than two cases
  • Two tests at once
FreeReading materialInteractive lab
4

Repeat — A row of circles, a staircase, a savings chart

By the end you can read a loop and say how many times it runs and what its variable holds each time, write a loop that places shapes, and add up as you go.

You build: A row of circles, a staircase, a savings chart

  • The same line, five times
  • for and range
  • The loop variable counts for you
  • What is inside the loop?
  • Counting from somewhere else
  • Adding up as you go
FreeReading materialInteractive lab
5

Loops That Think — A checkerboard; a brick wall

By the end you can make a decision on every turn of a loop, use a remainder to pick out every second or third turn, count and find a best value as you go, read a loop inside a loop, and write a while loop that stops when something changes.

You build: A checkerboard; a brick wall

  • A decision on every turn
  • Remainders
  • How many passed?
  • The best one so far
  • A loop inside a loop
  • Until something changes
FreeReading materialInteractive lab
6

Functions — A flower garden; a click-to-draw tool; a target game

By the end you can define a function and call it, pass values in and hand a value back, tell showing a value from returning it, say which names live inside a function, build one function out of others, and write a function that runs when the picture is clicked.

You build: A flower garden; a click-to-draw tool; a target game

  • Your own instruction
  • Define is not do
  • Values in
  • A value out
  • Showing is not returning
  • Names that stay inside
FreeReading materialInteractive lab
7

Strings — Letter tiles; a text bar chart

By the end you can pick out a character or a piece of a string, loop over its characters, ask whether one piece of text is inside another, use methods that give back a new string, build a string step by step, and put numbers into text with an f-string.

You build: Letter tiles; a text bar chart

  • Text has positions
  • From the end, and in pieces
  • One character at a time
  • Is it in there?
  • Methods give you a new string
  • Building text
FreeReading materialInteractive lab
8

Lists — A scoreboard

By the end you can read and replace items by position, loop over a list, add and remove items, build a new list in a loop, choose between looping over the items and looping over the positions, and move between text and a list of words.

You build: A scoreboard

  • Many values, one name
  • Lists can change
  • Every item in turn
  • Adding and removing
  • Building a list
  • When you need the position
FreeReading materialInteractive lab
9

References and Grids — A seating chart; a pixel grid

By the end you can say how many lists a program has made, make a real copy when you need one, tell a function that changes your list from one that only looks at it, read and write the cells of a grid, and build a grid whose rows are separate lists.

You build: A seating chart; a pixel grid

  • Two names for one list
  • A copy is a second list
  • Functions and your lists
  • Rows of rows
  • Row, then column
  • Three rows, or one row three times?
FreeReading materialInteractive lab
10

Dictionaries and Sets — A letter chart; a word chart

By the end you can look a value up by its key, add and change entries and deal with a key that is missing, loop over a dictionary, count things with one, use a set to ask "have I seen this?", and choose between a list, a dictionary and a set by the question you need answered.

You build: A letter chart; a word chart

  • Looking up by name
  • New keys, changed values, missing keys
  • Every key and its value
  • Counting things
  • Seen it before?
  • Which one do I need?
FreeReading materialInteractive lab
11

Find the Bug — Six repaired programs, each with the test that proves the repair

By the end you can read an error report from the bottom, tell the common kinds of error apart, find the first value that is not what you expected, state what must be true with assert, choose the test cases that matter, and write the test that fails before you fix the bug.

You build: Six repaired programs, each with the test that proves the repair

  • Crashes and wrong answers
  • Reading a traceback
  • Five kinds of error
  • Find the first wrong value
  • Say what must be true
  • The cases you did not picture
FreeReading materialInteractive lab
12

Build a Game — Tic-Tac-Toe with guidance, then a second game from a description alone

By the end you can keep a game's whole situation in data and draw the picture from it, say what must be remembered between clicks and keep it in one place, check that a move is allowed before changing anything, and plan a program as a list of small functions before writing any of them.

You build: Tic-Tac-Toe with guidance, then a second game from a description alone

  • The data is the game
  • Remembering between clicks
  • Check, then change
  • Plan before you type
  • Build in stages, test each stage
FreeReading materialInteractive lab
13

Pythonic Data Work — A leaderboard; a before-and-after chart

By the end you can get the position and the item together with enumerate, walk two lists side by side with zip, build and filter a list in one line, use sum, min and max, sort with sorted, say what to sort by with key=, and tell when a plain loop is still the better choice.

You build: A leaderboard; a before-and-after chart

  • The position and the item together
  • Two lists side by side
  • A new list in one line
  • Keeping only some
  • Total, smallest, largest
  • In order
FreeReading materialInteractive lab
14

Recursion — Squares inside squares; the size of a folder of folders

By the end you can write a function that calls itself on a smaller input, give it a case that stops, say what each waiting call is holding, write one step and trust the smaller call for the rest, follow data that holds smaller data of the same kind, and tell when a function that calls itself twice is doing far too much work.

You build: Squares inside squares; the size of a folder of folders

  • A function that calls itself
  • The case that stops
  • Calls that wait
  • Trust the smaller call
  • Data inside data
  • When one call makes two
FreeReading materialInteractive lab

Part 2 · Solve problems10 modules · free lessons, paid labs

15

Stacks — A bracket checker; a calculator; a chart of days waiting for warmer weather

By the end you can use a list as a stack, guard against an empty one, match pairs that nest, keep a history to go back through, evaluate an expression with a stack, let items wait on a stack until their answer arrives, and count the work a loop does when counting the loops is misleading.

You build: A bracket checker; a calculator; a chart of days waiting for warmer weather

  • Last in, first out
  • Looking without taking
  • Matching pairs
  • Going back
  • Operands that wait
  • Waiting for an answer
  • Counting the work
Free lesson · Paid labReading materialGuided lab
16

Queues and Breadth-First Search — A map of distances through a maze; the shortest way through it

By the end you can use a queue, say why a list makes a poor one, search a grid ring by ring, mark places at the right moment, build a map of distances, recover the shortest path by walking back, run the same search on things that are not grids, and start it from several places at once.

You build: A map of distances through a maze; the shortest way through it

  • First in, first out
  • A queue that does not shuffle
  • Searching in rings
  • Seen when added
  • How far?
  • Which way?
  • Not only grids
  • Several starts at once
Free lesson · Paid labReading materialGuided lab
17

Build a Cache — A cache that forgets the right thing; a chart of how often it saves the work

By the end you can put a cache in front of a slow function, give it a limit, forget the oldest arrival, forget what has gone longest unused, keep keys in order of use, use a dictionary that remembers order, and measure a cache by its hit rate.

You build: A cache that forgets the right thing; a chart of how often it saves the work

  • Do not work it out twice
  • A cache with a limit
  • Forget the oldest arrival
  • Forget what has gone longest unused
  • Keeping the order of use
  • A dictionary that remembers order
  • Measure it
Free lesson · Paid labReading materialGuided lab
18

Lookup in One Pass — A pair finder that reads its list once; a chart of the work two methods do

By the end you can say what comparing every pair costs, turn a question about pairs into a lookup, put the asking and the storing in the right order, spot a repeat as it happens, group items by something they share, and choose that something.

You build: A pair finder that reads its list once; a chart of the work two methods do

  • Every pair is too many
  • Ask for what you need
  • Look, then store
  • Seen it before
  • Groups
  • Choosing the key
Free lesson · Paid labReading materialGuided lab
19

Two Ends of a Sorted List — A pair finder that needs no memory; a merge of two sorted lists

By the end you can say what a sorted list lets you conclude from one comparison, walk two positions inward, argue that nothing is missed, decide when sorting first is worth it, walk two sorted lists together, and rearrange a list in place with a reader and a writer.

You build: A pair finder that needs no memory; a merge of two sorted lists

  • What sorted gives you
  • One position at each end
  • Why nothing is missed
  • When the list is not sorted
  • Two lists, a position in each
  • A reader and a writer
Free lesson · Paid labReading materialGuided lab
20

Halving — A search that finds one item among a million in twenty looks; a van just large enough

By the end you can halve a range, keep its two ends straight, say how many looks a search needs, find the first position that is large enough, and use halving to search for an answer when there is no list at all.

You build: A search that finds one item among a million in twenty looks; a van just large enough

  • Guess the number
  • Low, high and the middle
  • What stays true
  • How many looks?
  • The first that is large enough
  • Searching for an answer
Free lesson · Paid labReading materialGuided lab
21

Sliding Windows — A chart of the busiest hour of a day; the longest stretch that keeps a rule

By the end you can describe a window by its two ends, update a total as a window slides, let a window grow and shrink to keep a rule, decide what a window has to remember, say why the work stays in step with the list, and put the measuring line in the right place.

You build: A chart of the busiest hour of a day; the longest stretch that keeps a rule

  • A window on a list
  • One leaves, one enters
  • A window that grows and shrinks
  • What the window has to remember
  • Counting the work
  • When to measure
Free lesson · Paid labReading materialGuided lab
22

Remember the Answer — A chart of calls before and after; the best way down a triangle of numbers

By the end you can find the questions a function asks more than once, keep its answers in a dictionary and look before working, decide what the key has to hold, tell when an answer is safe to remember, and work out what a remembered function costs.

You build: A chart of calls before and after; the best way down a triangle of numbers

  • The same question, again and again
  • Remember each answer
  • What is the key?
  • Where you are, not how you got there
  • Counting the work
  • Where it goes wrong
Free lesson · Paid labReading materialGuided lab
23

Fill the Table — A festival plan with the chosen nights picked out; a table of two words compared

By the end you can turn a remembered function into a table, choose an order of filling in which nothing is read before it is ready, build a table with rows and columns, walk back through a table to find the choices behind the best value, keep only the part of a table that is still needed, and decide between a memo and a table.

You build: A festival plan with the chosen nights picked out; a table of two words compared

  • From a memo to a table
  • The order of filling
  • A table with two sides
  • Getting the choices back
  • Keeping only what is needed
  • Memo or table?
Free lesson · Paid labReading materialGuided lab
24

Which Pattern? — A slow answer and a fast one for the same problem, checked against each other

By the end you can find the detail in a problem that points at a pattern, write the slow answer first and say what it costs, check a fast answer against the slow one, say what a pattern needs to be true before relying on it, and state the promise of a loop before writing it.

You build: A slow answer and a fast one for the same problem, checked against each other

  • The problem does not say
  • The detail that decides
  • The slow answer first
  • Check the fast against the slow
  • What the pattern needs
  • Say the promise
  • A routine
Free lesson · Paid labReading materialGuided lab

What is different

  1. Predict before you run

    Most activities start by asking what a program will do. Then you run it and see whether you were right.

  2. Step through every line

    Go through your program one line at a time and see each value, each list and each call as it changes.

  3. Checks say what went wrong

    They test your program with other inputs too, and tell you which case it got wrong and what it produced.

Build with Python: frequently asked questions

Do I need to install Python?

No. Every lab runs in your browser, so there is nothing to install, and the free modules need no account. Your code stays on your device.

Is it real Python?

Yes. The labs run standard Python (CPython, compiled to WebAssembly by Pyodide) in your browser. The drawing instructions such as canvas, rectangle and circle come from a small module made for this course; everything else is the Python you would install on your own computer.

Is Build with Python free?

The fourteen foundation modules are free, lessons and labs. Every advanced lesson is free to read as well. A one-time purchase unlocks the labs of the ten advanced modules.

What does the purchase include?

The labs of modules 15–24: stacks, queues and breadth-first search, a cache, one-pass lookup, two ends of a sorted list, halving, sliding windows, remembering answers, filling a table, and a last module where nobody names the technique. That is 151 activities with 282 checks, including checks that count the work your code does, so a slow answer does not pass as a fast one.

Do I need any programming experience?

No. Module 1 starts with a single drawing instruction and takes it apart. Each module uses only what the ones before it taught.

What will I build?

A robot and a house, a sunset run by three variables, a checkerboard, a flower garden, a scoreboard, a pixel grid, a letter chart, Tic-Tac-Toe, and a second game from a description alone. In the advanced track: a bracket checker, a calculator, a shortest route through a maze, a cache, and fast answers checked against slow ones.

How is this different from other beginner Python courses?

Most activities ask you to predict what a program will do before you run it. Then you can step through it line by line and see every value change, and checks tell you what your own code got wrong. The aim is that you can say why a program does what it does.