← back to the map

chapter 00 · part 1

Python in 20 minutes

the hook

You'll write real AI code in this app. Here's every piece of Python you need — nothing more.

the idea

You don't need to already know how to code to finish this lab. But you do need about 20 minutes of Python — the same 20 minutes every playground after this one leans on. Let's get it out of the way, once, properly.

A variable is a labeled box. `age = 25` puts 25 in a box called age. That's it. No math-class flashbacks required.

A list is a row of boxes, numbered from 0. `fruits = ["apple", "banana"]` — `fruits[0]` is "apple", because counting starts at zero, not one. This trips up literally everyone, once. Now it won't trip up you.

A function is a labeled recipe. Write it once — `def greet(name): return "hi " + name` — then call it as many times as you want. Every model you'll build later in this app is really just a giant pile of function calls.

A loop repeats an action without you retyping it. `for x in [1, 2, 3]: print(x)`. Training a model is a loop too — predict, check, adjust, repeat, thousands of times. Below, you'll write the small version.

playground — your hands now

what: run 4 tiny python cells — variables, lists, functions, loops.

why: every playground after this one assumes you know these 4 things. 20 minutes now saves confusion later.

how: work top to bottom, run each cell, read the output before moving on.

start here → run each cell top to bottom, in order.

1 · variables

what: store your name and age in labeled variables.

why: every program — including every model in this app — starts by holding values in named variables.

how: fill the blanks, press run, read the output.

predict first: once you fill in the blanks, what will print?

fill in your name and age, then hit run.

name = "" age = print(name, "is", age, "years old")

2 · lists

what: read items out of a list by their index.

why: tokens, weights, embeddings — nearly everything in an LLM lives in lists you index into.

how: drag the 4 lines into the right order, press run.

predict first: once these lines are in the right order, what prints FIRST?

these 4 lines got scrambled — drag them into an order that makes sense, then run.

⠿
fruits = ["apple", "banana", "cherry"]
⠿
print(fruits[0])
⠿
print(fruits[2])
⠿
print(len(fruits))

3 · functions

what: write a function that returns a greeting.

why: every layer of a neural net is just a function — write one now, ch4 onward is just bigger versions of this.

how: fill in the return line, press run — stuck? tap 'need a hint?'

predict first: once greet() is fixed, what will print(greet("Asha")) output?

finish the greet function so it returns 'hi ' plus the name. stuck? there's a hint button.

4 · loops

what: print the numbers 1 through 5 with a loop.

why: training a model IS a loop — predict, check, adjust, repeat. this is that loop, shrunk down.

how: write a for loop from scratch, press run.

predict first: what will your finished loop print?

freehand this one — write a loop that prints the numbers 1 through 5, one per line.

try this

Run all four cells below in order. Then go back and break one on purpose — delete a colon, misspell a variable name, remove a bracket — and read the error that comes back. Errors aren't punishment. They're the interpreter telling you exactly what confused it, in plain terms.

checkpoint

1. In `fruits = ["apple", "banana", "cherry"]`, what is `fruits[1]`?

2. Why bother writing a function instead of just copy-pasting code?

recap card — keep this

variables hold things, lists hold many things, functions are reusable recipes, loops repeat.

next chapter → What is a language model?