How code runs — the notional machine
September 16, 2026
This is a course about telling a computer what to do, precisely.
Over 14 lectures we go from “what even is a program?” to reading text off the web and processing it.
No prior experience assumed. The only requirement is willingness to be precise and to be wrong often — errors are how we learn here.
Today you will see some code, but the goal is not yet to write your own. We use it for one thing: to watch a program run in sequence — one instruction after another, in the order you wrote them, and nothing happening in between that you did not ask for.
That sequential nature is the whole of today. Get that picture right and everything later is easier.
| Block | Lectures |
|---|---|
| Thinking like a machine | 1–2 (today + next) |
| Data & control flow | 3–4 |
| Structuring code | 6, 7, 9, 10 |
| Text & the web | 12, 13 |
| Hands-on with the tutor | 5, 8, 11, 14 |
Four sessions (5, 8, 11, 14) are practicals: you write code, the tutor helps.
| Where | Polo di Rovereto — Palazzo Piomarta, corso Bettini 84 |
| Attendance | Not compulsory — but the practicals are hands-on, so come |
| Office hours | By appointment |
One individual practical exam, in class: you solve a series of programming exercises on the topics of the course. No written theory paper, no syntax to recite from memory.
What that means for how you should work:
Exam dates are published from around December.
Everything lives on Moodle: slides, worked solutions, announcements. Enrol today — didatticaonline.unitn.it, course 44040
There is no compulsory textbook. The slides and the worked exercise solutions are the course material.
Optional further reading, both available through the UniTrento libraries:
Neither is required. Take Sweigart if you want a second voice explaining the basics; take Hammond for the linguistic angle this course picks up later.
A recipe is a list of instructions, carried out in order, that transforms ingredients into a result.
A program is a list of instructions that a computer carries out in order, transforming data into a result.
The computer is fast and obedient, but utterly literal. It does exactly what you write, even when you meant something else.
Imagine an assistant who:
Learning to program is learning to write instructions for this assistant.
Hello, World!
print(...) is an instruction: “display this on the screen”."Hello, World!", is the data it acts on.print is built in: Python already knows this word. It is one of a few dozen the machine starts with, so you never have to explain it. Ask for a word it does not know and it stops — exactly like our literal assistant.
You will never watch electrons move through the CPU. Instead you keep a simplified, predictable model of the machine in your head and use it to predict what the code will do.
The notional machine is the simplified mental model of the computer that executes your code — just detailed enough to predict a program’s behaviour, and no more.
Expert programmers are not people who memorised syntax. They are people whose notional machine is accurate.
For now, three parts are enough:
print writes output we can see.Execution = move the finger down the lines, doing what each says, updating memory and the screen.
The finger starts at line 1 and moves down:
first
second
third
Order is not decoration. Swap the lines and the output changes.
“Tracing” = pretending to be the notional machine and writing down what happens at each step. This is the single most useful skill in this course.
A
B
C
| Step | Finger at | Action | Screen so far |
|---|---|---|---|
| 1 | line 1 | display A |
A |
| 2 | line 2 | display B |
A B |
| 3 | line 3 | display C |
A B C |
When unsure what code does — trace it.
The machine does not read your intentions. This line is missing a closing quote, so the machine cannot make sense of it and stops:
Cell In[4], line 1 print("Hello, World!) ^ SyntaxError: unterminated string literal (detected at line 1)
An error is not the machine being mean. It is the machine telling you exactly where it stopped understanding. Read the message — it is a gift.
The second kind is sneakier: the machine will not warn you, because as far as it is concerned nothing is wrong. Syntax errors it finds for you. Logic errors only tracing will.
Our notional machine says memory is a set of labelled boxes holding values. But a computer is electronics: there are no letters in there, and no numbers either — only circuits that are carrying current, or not.
So how does "Hello, World!" fit inside a machine that can only tell on from off?
We open the lid once, look inside, and close it again.
Take 123. The same digit means something different in each position:
| Position | 100 | 10 | 1 |
|---|---|---|---|
| Digit | 1 | 2 | 3 |
100 × 1 + 10 × 2 + 1 × 3 = 123
We have ten digits, 0–9, so each position is worth ten times the one to its right. Nothing in nature forces that ten — it is just how many fingers we happen to have.
A circuit either stores electricity or it does not. That gives exactly two digits: 0 and 1.
A binary digit is a bit — the smallest thing a computer can remember.
With ten digits, each position was worth ten times the previous one. With two digits, each position is worth twice the one to its right.
So how do we count past one?
Three positions, worth 4, 2 and 1. Add up the positions holding a 1:
| 4 | 2 | 1 | Value |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 2 |
| 0 | 1 | 1 | 3 |
| 1 | 0 | 0 | 4 |
| 1 | 0 | 1 | 5 |
| 1 | 1 | 0 | 6 |
| 1 | 1 | 1 | 7 |
That is all binary is.
Three bits are full: 111 is seven, with nowhere left to carry.
So we do what decimal does when it runs out at nine — add a position:
| 8 | 4 | 2 | 1 |
|---|---|---|---|
| 1 | 0 | 0 | 0 |
n bits hold 2ⁿ different values. Eight bits — one byte — give 256 of them: 00000000 to 11111111, or 0 to 255.
Bits give us numbers. Text is then just an agreement about which number means which character.
Once that check fell out of use, every country spent the spare bit on its own alphabet — in different ways. That is why text from elsewhere still arrives broken.
Python knows both agreements, so we can just ask:
65 0b1000001
🧠 129504
There is only one kind of stuff inside the machine: numbers, stored as bits. Everything else is an agreement about how to read them.
Pick the wrong agreement when reading a file and text comes out as garbage. We meet that again in lecture 10, reading real text off the web.
You now know what is in the boxes. For the rest of this course you can forget it.
We work at a higher level: we write "Hello, World!" and Python deals with the bits. That is what a high-level language means — and why Python reads almost like English.
Back to the notional machine: instructions in, results out, labelled boxes in between.
Two things, and the first one brings Python with it.
We install all of this together, right now. There is nothing to work out on your own tonight.
Use the classroom computer today, even if you brought your own laptop. It is the very machine you will sit the exam on, so the sooner it feels familiar the better. Set up your own laptop as well if you like — but do today’s work here.
Already using Anaconda? Keep it — it contains everything Miniconda has.
Windows
macOS
Then download VS Code from its website and install it normally.
If a step fails, stop and bring the laptop to class. Losing an evening to an installer is the worst possible first experience of programming.
A terminal is a window where you type a command as text and the computer answers as text. No buttons, no menus, no icons.
It looks primitive, and it is — but it is the most direct way to tell a computer to do something, and it is how we will start Python.
Windows
Start menu → Anaconda Prompt
macOS
Applications → Utilities → Terminal
You type one line, press Enter, the machine does it and waits for the next. That is our literal assistant again — one instruction at a time, in order.
From now on the commands are the same on both systems — that is the whole point of installing conda. Open your terminal and type:
intro2python.(intro2python) prefix.Python 3.12.x.Anything you install inside this environment cannot break anything else on your computer. That is why we bother.
VS Code does not find the environment by itself. Two steps, once:
Ctrl+Shift+P (Cmd+Shift+P on macOS) to open the Command Palette, type Python: Select Interpreter, and pick intro2python.Quicker, once a .py file is open: the interpreter in use is shown in the status bar at the bottom right. Click it and the same list appears — that is also how you check, at a glance, which Python you are about to run.
Skip step 2 and your code will run against the wrong Python. This is the single most common reason a beginner’s setup “doesn’t work” — so we will do it together, on your screen, in class.
The interactive shell (REPL) — in your terminal, with the environment active, type python. You get a >>> prompt: one line in, result straight back. Great for experiments.
A script — a file (e.g. hello.py) with many lines, run all at once. This is how real programs live.
Same notional machine underneath; just different ways to feed it instructions.
Programming is a loop you go round again and again:
Beginners fear step 3. Good programmers seek it — the feedback is the point.
A notebook is a file split into cells. You run one cell at a time and its output appears right underneath it.
It is a hybrid of the two we just saw:
Notebooks have the extension .ipynb. The worked solutions to every exercise in this course are notebooks — so you need to be able to open one.
Two steps, once — we do them together now:
Then in VS Code install the Jupyter extension, next to the Python one you already added.
To use it: create a file ending in .ipynb, click Select Kernel at the top right and pick intro2python. Write code in a cell, press Shift+Enter to run it.
A warning that matters today: you can run cells in any order you like. The machine still executes one instruction at a time — but your reading order and its execution order may no longer match. When a notebook stops making sense, run the cells again from the top.
Next lecture: which values those boxes hold and how they change (state), and the rules for which names are visible where (scope).
Without running anything, trace this program on paper and write the exact screen output:
one
two
one
done
Then run it and compare. Did your notional machine agree with the real one?
Each snippet has one problem. Predict the error message the machine will give, then check.
Cell In[7], line 2 print("Good morning) ^ SyntaxError: unterminated string literal (detected at line 2)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[8], line 2 1 # (b) ----> 2 Print("Good morning") NameError: name 'Print' is not defined
Cell In[9], line 2 print "Good morning" ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
Explain in words why each one stops the literal machine.
Write a program that prints exactly these four lines, in this order:
Ready Set Go Ready
Then, without adding or deleting lines, reorder your existing lines so the output becomes Go / Set / Ready / Ready. What does this tell you about instruction order?
Intro to Programming (Python) · Fall 2026