P01.1 · How computers run programs
P01.1 L0 · Foundation 4 lessons · about 100 min Live · in review
Part of P01 Python from Zero in the Programming and Data track.
What actually happens when a computer runs a program. These four lessons name the parts that do the work and trace a four-line program by hand, follow Python’s text through translation to bytecode and on to a running program, set up Python to run at its prompt and as a script, and open up memory to show that numbers, letters and the pixels of a picture are all stored as bits.
What you need first. School arithmetic and a computer on which you may install a program. No programming is assumed: this is the first module of P01 Python from Zero.
Lessons
A program is a list of instructions P01.1.1 25 min
A program is a text of instructions that a computer carries out one at a time, top to bottom, exactly as written. Meet the parts that do the work, trace a four-line program by hand in a trace table, and see why swapping two lines changes what it prints.
From source text to running program P01.1.2 25 min
A processor understands only its own machine instructions, so Python translates your text first: it compiles the whole file to bytecode, then its virtual machine runs that one step at a time. Worked on two broken files, one that never starts and one that stops halfway.
Running Python yourself P01.1.3 25 min
Install Python, check its version and run it two ways: at the interactive prompt, a read, evaluate, print loop that shows the value of whatever you type, and as a script, which shows only what it prints. Then read a first error message from its last line upwards.
Bits, bytes and memory P01.1.4 25 min
Everything in a computer’s memory is a pattern of 0s and 1s. Work binary place value by hand, see why a byte counts from 0 to 255, store letters as numbers and a grey image as a grid of numbers, and picture memory as a long row of numbered cells.
The interactive
P01.1-X1 · Line-by-line stepper. Step forward and back through a four-line program and watch the current-line marker move and the output grow one line at a time. Move a line to reorder the output, or plant a missing bracket or a misspelt name and see how far the program gets. It lives in From source text to running program.