← learn.jakobbeck.com
MøllerBeck · Phase 1 Reference
How Code Actually Works
The mental models underneath everything you'll write. Read this before the Python Primer. Return here whenever something feels abstract.
▶ Phase 1 · Read First
Start here. Everything else in this primer is an elaboration of one idea: a program is a list of instructions that a computer follows, line by line, in order. That's it. The complexity comes from what kinds of instructions are possible — not from anything more mysterious than that.
The core idea
A program is a recipe
Instructions executed in sequence, top to bottom
When you run a Python script, Python reads your file from the first line to the last and executes each instruction in order. It doesn't skip around. It doesn't guess what you meant. It does exactly what each line says, then moves to the next.

If a line fails — a typo, a missing file, a value that doesn't exist — Python stops and tells you. It doesn't try to work around the problem.
What happens when you run python3 summariser.py
1
import csv
Python loads the csv library — a set of tools for reading CSV files. This happens before anything else.
2
company_name = "Vestas Wind Systems"
Python reserves a slot in memory, labels it "company_name", and stores the text "Vestas Wind Systems" there.
memory: company_name → "Vestas Wind Systems"
3
employees = 400
Another memory slot. "employees" now points to the number 400.
memory: employees → 400
4
print(f"Client: {company_name}")
Python looks up "company_name" in memory, gets "Vestas Wind Systems", inserts it into the string, and displays the result in the terminal.
terminal output: Client: Vestas Wind Systems
5
# end of file
Python reaches the end. The script stops. Memory is cleared. The terminal prompt returns.
Why this matters for MøllerBeck
Your briefing summariser will have maybe 30–40 lines. Python will execute each one in order: open the CSV file, read the first row, format it, write it to the output file, read the second row, and so on. Understanding that programs execute top to bottom tells you where to look when something goes wrong: find the line that failed, look at what came before it.
The key distinction
Writing code vs running code
Two separate moments — easy to confuse at first
Writing code happens in VS Code — you type instructions into a .py file and save it. Nothing executes yet. The file just sits on disk.

Running code happens in the terminal — you type python3 script.py and press Enter. Python reads your file and executes every instruction. This is when things happen.

This is why saving before running matters so much. If you edit the file but don't save, the terminal runs the old version — the one that was on disk before your changes.
The loop you'll repeat hundreds of times: write a line → save → run → read the output → write the next line. Get comfortable with this rhythm. It's the whole job.
Variables are the single most important concept in programming. Everything else — loops, functions, files — is just variables moving through more complex operations. If this clicks, everything else clicks faster.
The core idea
A variable is a named box in memory
Give a value a name so you can use it anywhere
Your computer has memory (RAM). When your program runs, Python uses some of that memory to store values. A variable is a label you attach to one of those memory slots — so you can find the value again, use it in multiple places, and change it when needed.
Memory — what Python is holding while your script runs
company_name
"Vestas Wind Systems"
string · text
employees
400
integer · whole number
revenue_m
14.7
float · decimal number
is_active
True
boolean · yes/no
When Python sees company_name later in your code, it looks up that label in memory and gets the value back. You never have to remember the actual memory address — you just use the name.
Without variables vs with variables
# WITHOUT variables — value repeated everywhere
print("Vestas Wind Systems")
print("Vestas Wind Systems" + " has 400 employees")
print("Sending briefing for Vestas Wind Systems")
# If the name changes, you edit 3 lines

# WITH variables — value stored once, name used everywhere
company_name = "Vestas Wind Systems"
print(company_name)
print(company_name + " has 400 employees")
print("Sending briefing for " + company_name)
# If the name changes, you edit 1 line
The spreadsheet analogy
You already use variables in Excel. Cell A1 contains "Vestas Wind Systems". You reference =A1 in formulas rather than typing the name everywhere. A Python variable is the same idea — a named container for a value. The difference: in Python, you name the container yourself rather than using a grid coordinate.
Variables don't have to stay the same. You can reassign them: employees = 400 then later employees = 450. Python updates the memory slot. The new value replaces the old one.
Every value has a type. Type determines what you can do with a value. You can add two numbers. You can join two strings. You can't add a number to a string — Python will refuse and tell you why. Understanding types prevents a whole category of errors.
The four types you'll use in Phase 1
What kinds of values exist
Each type has different rules for what operations are valid
String · str
Text. Always wrapped in quotes — single or double, as long as they match.
"Vestas Wind Systems"
'Energy'
"400" ← this is text, not a number
Used for: names, industries, any human-readable text in your CSV
Integer · int
A whole number. No quotes, no decimal point. Can be negative.
400
-12
29000
Used for: employee counts, years, any countable whole number
Float · float
A number with a decimal point.
14.7
0.5
1000.0
Used for: revenue figures, percentages, anything with fractions
Boolean · bool
Exactly two possible values: True or False. Capital first letter — required.
True
False
Used for: is_active, is_priority — any yes/no state in your data
Why types matter — a real error
employees = 400          # integer
label = "Employees: "   # string

print(label + employees)
# ❌ TypeError: can only concatenate str (not "int") to str
# Python refuses — you can't join text and a number directly

print(label + str(employees))
# ✓ Convert the integer to a string first
# Output: Employees: 400
Why computers care about types
A computer stores a number and a piece of text completely differently in memory — different binary format, different operations available. When you ask Python to add "400" (text) and 400 (number), it genuinely doesn't know what you want. Concatenate them into "400400"? Add them arithmetically to get 800? Types are how you tell it which one.
Operations are what you do to values. Combine them, compare them, transform them. Most of programming is just deciding which operation to apply to which values, and in what order.
The main categories
What you can do with values
Arithmetic, comparison, and combination
Arithmetic — on numbers
Standard maths. Works on integers and floats.
400 + 50 → 450
29000 - 400 → 28600
revenue * 1.1 → 10% increase
employees / 4 → per quarter
employees % 2 → remainder (odd/even check)
Combination — on strings
Join strings together with +. Repeat with *.
"Vestas" + " " + "Wind"
→ "Vestas Wind"

"—" * 20
→ "————————————————————"
Comparison — produces True/False
Compare two values. The result is always a boolean — used in if-statements.
employees > 500 → True or False
industry == "Energy" → True or False
name != "Vestas" → True or False
revenue >= 10.0 → True or False
Logic — combining conditions
and, or, not. Combine multiple comparisons into one decision.
employees > 500 and industry == "Energy"
→ True only if BOTH are true

employees > 500 or revenue > 100
→ True if EITHER is true
Operations in context — your briefing summariser
employees = 400
revenue = 14.7
industry = "Energy"

# Comparison — produces True or False
if employees > 200 and employees <= 500:
    size_label = "Mid-size"

# Arithmetic — transform a value
revenue_per_employee = revenue / employees * 1000

# String combination — build output
summary = size_label + " company in " + industry
print(summary)
# Output: Mid-size company in Energy
A function is a named, reusable block of instructions. You define it once. You call it as many times as you need. It takes inputs, does something, and gives back an output. Functions are how you stop repeating yourself.
The core idea
Package instructions so you can reuse them
Define once · call many times · inputs in · output out
A function is a machine
client dict
{"name": "Vestas", "employees": 400}
format_client()
the function
formatted string
"Vestas · 400 employees · Mid-size"
# Define the function — this runs ZERO times when Python first reads it def format_client(client): name = client['name'] count = client['employees'] if count > 500: size = "Large" else: size = "Mid-size or smaller" return f"{name} · {count} employees · {size}" # Call the function — this is when it actually runs result = format_client({"name": "Vestas", "employees": 400}) print(result) # Output: Vestas · 400 employees · Mid-size or smaller
def — short for "define." Tells Python you're creating a function.
Parameters — the inputs in parentheses. client is a placeholder name for whatever you pass in when you call it.
return — sends a value back out. Without return, the function does its work but nothing comes out the other end.
Why functions matter for your project
Your CSV will have 10, 20, maybe 50 clients. Without a function, you'd write the formatting logic 50 times. With a function: write it once, call it in a loop, it runs for every client automatically. This is where loops and functions combine — the loop feeds each row to the function one at a time.
A file is data that persists when your program stops. Variables exist only while the program runs — when it stops, memory clears and they're gone. Files live on disk and survive between runs. Reading and writing files is how your program interacts with the real world.
The core idea
Memory vs disk
Variables live in RAM · files live on disk · files survive, variables don't
Your briefing summariser — the full data flow
clients.csv · on disk
Name,Industry,Employees
Vestas,Energy,29000
Ørsted,Energy,7000
Grundfos,Engineering,19000
Novo Nordisk,Pharma,55000
summariser.py · runs in memory
open clients.csv
read each row as a dict
call format_client(row)
collect formatted output
write to briefing.txt
briefing.txt · on disk
Generated: 12 May 2026
Clients: 4
——————————————
Vestas · Energy · Large
Priority client ★
Reading a file · writing a file
# Reading — "r" means read-only
with open("clients.csv", "r") as f:
    # everything inside here can use f
    contents = f.read()
# file is automatically closed when the with block ends

# Writing — "w" means write (overwrites if file exists)
with open("briefing.txt", "w") as f:
    f.write("MøllerBeck Client Briefing\n")
    f.write("Generated: 12 May 2026\n")

# Appending — "a" adds to end without overwriting
with open("briefing.txt", "a") as f:
    f.write("Vestas · Energy · Large\n")
The file must be in the right place. When your script says open("clients.csv"), Python looks for it in the same folder the script is running from. If the file is somewhere else, you get a FileNotFoundError. This is one of the most common Phase 1 errors — always check which folder you're in when you run.
Execution is what happens the moment you press Enter after typing python3 script.py. Understanding this sequence tells you where to look when things go wrong — and things will go wrong.
The full picture
From you pressing Enter to output appearing
What Python actually does with your file
python3 summariser.py — the execution sequence
1
You type: python3 summariser.py
Your Mac finds the Python program and tells it to run your file. Python is the interpreter — it reads Python code and translates it into instructions your CPU can execute.
2
Python reads the entire file first
Before executing anything, Python checks for obvious syntax errors — missing colons, unmatched quotes. If it finds one, it stops here and shows you a SyntaxError with a line number.
3
Python executes line 1, then line 2, then line 3...
Top to bottom, in order. Import statements run first (loading libraries). Variable assignments store values in memory. Function definitions are registered but not run yet. Loops and function calls execute when Python reaches them.
4
Output appears in the terminal
Every time Python hits a print() call, the value appears in your terminal immediately — not all at once at the end. This is why print() is your best debugging tool: you can see what's happening at each step.
terminal: Vestas · 29000 employees · Large
5
If an error occurs at any point
Python stops immediately, prints a Traceback (the error report), and returns control to you. Nothing after the error line runs. Read the last line of the Traceback first — that's the error type and message. The line above it tells you where.
6
Script finishes — memory clears
When the last line executes successfully, Python stops. All variables disappear — they existed only in RAM during the run. Only files written to disk survive. Your terminal prompt returns.
The key insight for debugging
When something goes wrong, Python tells you the line number. Go to that line in VS Code. Then look at what came before it — what variables were set, what files were opened, what the loop was doing. Errors are almost always caused by something a few lines earlier, not by the line Python points to. The pointed line is where Python gave up, not necessarily where the mistake was made.
print() is your microscope. When you don't understand what your code is doing at a particular point, add print(variable_name) on the line before the problem. See what value is actually in there. It's almost always different from what you expected — and that difference is the bug.