TwiddleLab / Courses / Code
How a Programmer Thinks
Give exact instructions, then watch variables, ifs and loops run step by step.
Lessons
- Instructions, Exactly (5 min): An algorithm is a list of exact steps that gets a job done.
- Variables Are Boxes (7 min): A variable is a named box that holds one value.
- Decisions: if (7 min): A condition like battery < 30 is always True or False (a boolean).
- Bugs Are Clues (7 min): An error message says where (the line), what kind (the error type) and the details.
- Loops: Do It Again (7 min): A for loop runs its indented body once for every value: each round is an iteration.
- Lists: Many Boxes in a Row (7 min): A list holds many values in order under one name: scores = [72, 45, 90].
- Sorting, One Swap at a Time (7 min): Sorting puts a list in order. Bubble sort compares neighbours and swaps them if they are in the wrong order.
- Finding Things Fast (7 min): Binary search checks the middle of a sorted list and throws away the half that can't hold the answer.
- Functions: Name a Recipe (7 min): A function is a named recipe: def gives the name and the steps.
- Build a Mini-game (7 min): input() asks the player to type something. It always gives back text.
Lessons are interactive and need JavaScript. Turn it on to play them.