PythonFoundational~6hPart 1 of 6

Python Foundations

Read it before you run it

Look at a Python program and say what it prints — then write one that turns a messy export into a report you would actually show someone. You run Python on your own machine. Nothing here runs the code for you.

Modules
8
Drills
18
Build steps
8
Time
~6h

Walk out with

A program that turns a messy listening history into a report you would screenshot — and the habit of tracing first.

What you'll do

01

Read it, then run it

Trace Python first. Install it when ready to build.

02

Follow the control

Decisions, loops, and calls — on paper, to the last line.

03

Calls, aliases, crashes

Trace a call, a shared list, and a traceback.

04

Print a report

A messy export in, a chart you would screenshot out.

The pitch

What you practise, and what you leave with

A report program: it reads a listening-history export, skips the broken rows, and prints a summary with a text bar chart.

You will practise

  • Trace a loop to its last number
  • Say which name still holds what
  • Read a traceback cold
  • Spot when two names share a list

Afterwards you can

  • Predict what a program prints
  • Fix a program from its traceback
  • Write a small file-to-report program
  • Design one boundary test

Modules

8 modules, 41 items

Lessons explain one idea. Drills repeat it until it sticks. Build steps make something that exists afterwards.

  1. 1

    Read a line before you write one

    ~46 min

    Look at a line and say its type, its value, and which name still holds what.

    • LessonSee what a line does7 min
    • LessonA name points, it is not a box9 min
    • DrillEvaluate the expression8 min
    • DrillName the type6 min
    • DrillAfter this, who holds what8 min
    • DrillWhat the string becomes8 min
  2. 2

    Read a decision

    ~37 min

    Name the branch that runs, and the operand Python never looks at.

    • LessonFollow the choice7 min
    • DrillWhich branch runs8 min
    • LessonAnd, or, and the skipped operand8 min
    • DrillWhat and/or hand back8 min
    • DrillTrue or false on the page6 min
  3. 3

    Trace a loop to its last iteration

    ~53 min

    Follow a loop on paper and be right about the number that comes out.

    • LessonFollow a loop to the end11 min
    • DrillThe value when it stops10 min
    • DrillHow many times the body runs10 min
    • DrillWhat range actually yields8 min
    • LessonThe last index is len minus one6 min
    • DrillOff by one at the edge8 min
  4. 4

    Follow a call in and out

    ~38 min

    Trace a call, tell a return from a print, and resolve the right n.

    • LessonWhere a call actually goes9 min
    • DrillWhat the whole program prints12 min
    • LessonLocal names and sticky defaults9 min
    • DrillWhich n is this8 min
  5. 5

    See the shared object

    ~35 min

    Predict when a change through one name is visible through another.

    • LessonTwo names, one list10 min
    • DrillLook it up8 min
    • LessonOne row, used twice7 min
    • DrillDoes the other name see it10 min
  6. 6

    Read the failure

    ~40 min

    Read a traceback, pick the handler, and find where it first went wrong.

    • LessonRead the red text12 min
    • DrillRead a traceback10 min
    • DrillWhich handler runs8 min
    • Build stepFind where it first went wrong10 min
  7. 7

    Get Python running

    ~34 min

    Install Python and an editor, give it a folder, run a file, drill the punctuation.

    • LessonPut Python on the machine8 min
    • LessonAn editor and a folder6 min
    • LessonRun a file, then break it10 min
    • DrillThe line that will not start10 min
  8. 8

    Build it

    ~1h

    Turn a messy export into a report you would show someone, then point it at your own data.

    • LessonThe report you will build10 min
    • Build stepSave the listening history4 min
    • Build stepSkip the rows that are broken12 min
    • Build stepMinutes for the busiest artist10 min
    • Build stepDraw the bars10 min
    • Build stepFour functions, one job each6 min
    • Build stepDesign one boundary test8 min
    • Build stepPoint it at your own data8 min

Read a program before you run it. Then write one worth showing.

The first item is free. ~6h of focused work, at your own pace.

Foundational~6h8 modules