The course

One path, in order. Each lesson is a small program you step through, watching the state change line by line — and most ship with the buggy version a beginner writes, watched failing. Start at the top, or jump to whatever you came for.

1Foundations: values & types

Before any algorithm: what a value is, the types a beginner meets, and how a name binds to a value.

  1. 1Values and namesA name points at one value — rebind it and the old value is gone, unless you saved it first.
  2. 2Numbers have types: int vs floatTwo ways to divide: // drops the remainder and gives an int, / keeps it and gives a float.
  3. 3Converting a float to an intint() truncates 3.9 to 3; round() gives 4 — watch which one you reach for.

2Arithmetic & division

How numbers combine: precedence, the power operator, and modulo — the remainder that wraps around.

  1. 4Operator precedence: × before +Watch 2 + 3 × 4 come out as 14, not 20 — Python does × before +.
  2. 5Powers: ** not ^Watch 2 ^ 3 silently give 1 — in Python ^ is XOR, and ** is the real power operator.
  3. 6Modular arithmetic: wrapping aroundWatch 10 + 5 read as 15 o'clock — and % wrap it back to 3.

3Comparisons & booleans

How a program asks a yes/no question: comparisons produce a bool, operators combine them, and most values are truthy or falsy.

  1. 7A comparison is a yes/no valueStore the result of age > 18 — a real bool — and watch > miss the boundary that >= keeps.
  2. 8Truthiness: what counts as trueA non-empty list is truthy but never equals True — watch == True skip the branch you wanted.
  3. 9and / or / notWatch x == 1 or 2 quietly become 2 (always truthy) — and the fix that compares both values.

4Decisions: the if / elif ladder

Putting conditions to work as control flow — where the order of branches is the whole game.

  1. 10Choosing one branch with if / elseWatch two separate ifs both run, the second clobbering the first — and elif pick just one.
  2. 11The elif ladder: order mattersWatch a 95 graded D because the loosest band was tested first — first true branch wins.
  3. 12FizzBuzzmilestoneMilestone: loops + if/elif + modulo — and the unreachable branch that grades 15 wrong.

5Programs & state

Tiny imperative programs, traced line by line — including the bugs that destroy or mis-store state.

  1. 13Swapping two valuesThree ways to swap two cups — including the one a beginner writes, watched failing.
  2. 14Adding up a listKeep a running total — and watch the = vs += bug stop it from ever adding.
  3. 15Running maximummilestoneMilestone: the accumulator + comparison — and a zero seed that breaks on all-negative data.
  4. 16Linear searchFind where a value lives — and watch the index-vs-value mix-up return the wrong thing.
  5. 17Filtering a listKeep the items that pass a test — and watch deleting-while-looping skip an element.
  6. 18Palindrome checkmilestoneMilestone: strings + indexing + comparison — and pairing the wrong letters.
  7. 19Collecting rainwatermilestoneMilestone: arrays, loops and min/max combine to trap water between columns — with a cool visual.

6Mutability & aliasing

Some values can be changed in place, and two names can point at one object — so changing 'one' changes 'both'.

  1. 20Aliasing: two names, one listWatch backup = scores share one list, so appending to one corrupts the other.
  2. 21Sorting into two pilesSplit numbers into evens and odds — and watch a one-character bug merge the piles.

7Functions

Packaging an idea you can call: a function opens its own scope, takes parameters, and must hand a value back.

  1. 22Functions: package an idea you can callThe same job four ways — see a function open its own scope and hand a value back.
  2. 23Parameters: order mattersWatch swapped positional arguments compute −70 left — and keyword arguments fix it.

8Data & representation

How computers store information — every bit of it a program you can trace.

  1. 24Decimal to binaryWatch 13 fill the powers-of-two columns to become 1101 — place value, traced as real Python.
  2. 25Binary to decimalTurn 1101 back into 13 by doubling — and watch the base mix-up read it as eleven hundred.
  3. 26Run-length encodingCompress a row of pixels into (length, colour) pairs — and watch the bug that drops the last run.
  4. 27OverflowWatch an 8-bit counter wrap 255 → 0 — and watch Python's unbounded ints refuse to.
  5. 28RoundoffWatch 0.1 + 0.2 come out as 0.30000000000000004 — and why == is a trap on floats.

9Systems & networks

How machines talk — modelled as small simulations and traced like any other program.

  1. 29Packet switchingsimulationFollow a packet hopping across a network graph from A to D, one hop at a time.
  2. 30Fault tolerancesimulationFail a node and watch a redundant network reroute — while a single-path one strands the packet.
  3. 31Packets take different routessimulationOne message, three packets, three routes — arriving out of order and reassembled by sequence number.
  4. 32Parallel speedupsimulationWatch two workers halve the time on independent tasks — and a dependency chain refuse to speed up at all.