Topic 0.1
What a Program Is
In one line
A program is a list of exact instructions that a computer follows in order. Almost every program takes some input, does some processing, and produces output; the text you write is called source code, and a mistake in it is called a bug.
Think of it like this
A recipe for making tea. "Boil one cup of water. Add one spoon of tea leaves. Wait two minutes. Pour into a cup." Anyone who follows the steps in order gets tea. A program is a recipe for a computer: a list of steps, written down, followed from top to bottom.
Words you'll meet
New words in this topic, in plain English. Come back here whenever one feels fuzzy.
- Program
- A list of exact instructions that a computer follows in order.
- Source code (code)
- The text of a program, as a person writes it.
- Programming language
- A strict language for writing programs, with exact rules. Python, Java and JavaScript are programming languages.
- Statement
- One instruction in a program, usually one line.
- Run (execute)
- To make the computer follow a program's instructions.
- Input
- The data that goes into a program.
- Output
- What a program produces, such as text shown on the screen.
- Bug
- A mistake in a program that makes it do the wrong thing.
- Debugging
- Finding and fixing bugs.
Step by step
01A program is steps in order
Here is a tiny Python program. Each line is one statement, and each statement says: show this text on the screen. You don't need to understand the details yet. Just read it top to bottom, the way the computer does.
print is Python's word for "show this on the screen". The text to show goes inside the round brackets, between quotation marks.
print("Boil one cup of water.")
print("Add one spoon of tea leaves.")
print("Wait two minutes.")
print("Pour into a cup.")02The order is the program
The computer runs line 1, then line 2, then line 3, then line 4. It never skips ahead and never goes back unless your code tells it to. If you swap two lines, you have written a different program: one that pours the tea before boiling the water.
This is why the first question to ask about any line of code is: what has already run before this line?
03Input, processing, output
The tea program only produces output. Most programs also take input and process it. The program below takes two prices (the input), adds them (the processing), and shows the total (the output).
apple = 30 tells Python to remember the number 30 under the name apple. A remembered value with a name is called a variable; Topic 1.1 covers variables properly. The + adds, exactly as in maths.
apple = 30 # input: the price of an apple
banana = 12 # input: the price of a banana
total = apple + banana # processing: add them
print("Total:", total) # output: show the answer04The computer has no common sense
A person asked to "add the prices" would ask what you meant if one price was missing. A computer does not ask. It follows the exact text. If you write apple + apple by mistake, it happily adds the apple twice and reports 60. Nothing looks broken; the answer is just wrong.
That is a bug: the program runs, but does something you did not intend. The computer was not confused. It did exactly what the code said.
apple = 30
banana = 12
total = apple + apple # bug: banana was meant here
print("Total:", total) # prints Total: 6005Two kinds of mistake
Some mistakes break the language's grammar rules, like a missing bracket. Python refuses to run the program at all and shows an error message pointing at the line. These are the simpler ones, because the computer tells you where to look.
Other mistakes follow the grammar perfectly but do the wrong thing, like adding the apple twice. Python cannot know what you meant, so it says nothing. You find these by checking the output against what you expected. Topic 0.7 teaches you to read error messages; testing (Phase 11) is how professionals catch the silent kind.
06From tiny steps to big programs
A real program is millions of tiny steps like these. Nobody writes millions of lines one by one: programmers group steps, give the group a name, and reuse it. print is itself such a group. Someone wrote the many steps needed to put text on a screen, named them print, and now you use them with one word.
An AI model answering your question is also a program. Its input is your text, its processing is a very large amount of arithmetic on numbers, and its output is more text. The code that feeds it your question and shows you the answer is ordinary Python of the kind you will write in this course.
Try it yourself
- 1
Change the order
In the first example, move the line
print("Pour into a cup.")to the top and press Run. Before you run it, say out loud what the first line of output will be.The computer did not notice that pouring first makes no sense. It ran the lines in the order you gave.
- 2
Change the input
In the second example, change
apple = 30toapple = 100and run it. Only one line of code changed, but two lines of output changed. Work out why before reading on:totalis calculated fromapple, so it changes too. - 3
Fix the bug
In the third example, change the buggy line to
total = apple + bananaand run it. You have just debugged your first program: you compared the output (60) with what you expected (42), found the line responsible, and fixed it.
Code & diagrams
Press Run. Then swap two lines and run it again: the output changes because the order changed.
Expected output
Boil one cup of water.
Add one spoon of tea leaves.
Wait two minutes.
Pour into a cup.Change the two prices and run it again. The processing stays the same; the output follows the input.
Expected output
Apple: 30
Banana: 12
Total: 42The program has a mistake on the line marked bug. Python does not complain, because the grammar is fine. Fix it so the total is 42.
Expected output
Total: 60Break it on purpose
Errors are the best teachers. Make each change, read the error, guess what went wrong, then reveal the answer.
Break #1
Leave out a closing bracket
In the first example, delete the last ) on the first line so it reads print("Boil one cup of water." and run it.
print("Boil one cup of water."
print("Add one spoon of tea leaves.")Break #2
Spell print with a capital P
Change the first print to Print and run it.
Print("Boil one cup of water.")Myth vs fact
Myth
Computers are smart, so they will work out what I mean.
Fact
Computers follow instructions exactly and guess nothing. All the cleverness is in the instructions that people wrote.
Myth
You need to be good at maths to program.
Fact
Most programming is careful thinking in steps, not maths. If you can write a clear recipe or give clear directions, you can learn to program. Some fields, such as machine learning research, do use more maths, and you can learn it when you need it.
Myth
Good programmers don't make mistakes.
Fact
Everyone writes bugs. Good programmers expect them, test for them, and fix them without panic.
Myth
If the program runs without an error, it is correct.
Fact
A program can run happily and still give the wrong answer, like the total of 60. Always check the output against what you expected.
Pro corner
Extra depth for experienced readers. New to this? Skip it for now and come back later.
- ▸
The input → processing → output shape scales all the way up. A web server takes a request and returns a response; a data pipeline takes files and writes tables; a language model takes text (cut into small pieces called tokens) and returns more text. When you meet an unfamiliar system, finding its inputs and outputs first is the fastest way to understand it.
- ▸
"The computer does exactly what you wrote" is the root of debugging. When behaviour surprises you, the program is not wrong about the code: your mental model of the code is wrong. Debugging is finding the first line where what you believed and what happened differ.
- ▸
Programs that call AI models add a new twist: the model's output can differ from run to run for the same input. The Python around the model is still exact and repeatable, which is why engineers put checks, validation and tests in the Python layer (Phase 16).
Remember this
- 1
A computer is very fast and very obedient, but it has no common sense. A person reading "add sugar" knows roughly how much. A computer must be told exactly: how much, when, and what to do if the sugar jar is empty. Programming is the skill of writing steps so exact that a machine with no common sense can follow them.
- 2
Almost every program has the same three parts. Input is what goes in (numbers you type, a file, a photo, a question to a chatbot). Processing is the work done on it (adding, sorting, searching, deciding). Output is what comes out (text on the screen, a saved file, an answer). A calculator, a game and an AI assistant all fit this shape.
- 3
The instructions you write are called source code, or just code. Code is plain text, written in a programming language: a small, strict language with exact spelling and grammar rules. Python is one such language. You will write Python code in files whose names end in
.py. - 4
The computer follows your code in order, one instruction at a time, starting at the top. Each instruction is called a statement. This order is the first thing to hold in your head when you read any program: what runs first, what runs next, what has already happened by this line.
- 5
The computer does exactly what you wrote, which is not always what you meant. A mistake in a program is called a bug, and finding and fixing mistakes is called debugging. Bugs are normal. Professional programmers write bugs every day; the skill is in finding them calmly.
- 6
Programs are built from a very small set of ideas that you will learn one phase at a time: remember a value (variables, Phase 1), decide (if, Phase 2), repeat (loops, Phase 2), and name a group of steps so you can reuse it (functions, Phase 5). Even the code that trains and runs AI models is made of these same four ideas, repeated at enormous scale.
Explain it without notes
In your own words, what is a program?
What are the three parts that almost every program has? Give an example of each for a calculator app.
What is a bug, and why can't the computer find every bug for you?
Why does the order of statements matter?
Practice
Write a program that prints the three steps for brushing your teeth, one per line, in the correct order.
Write a program that remembers the prices of a pen (10) and a notebook (45), adds them, and prints Total: 55.
This program should print the cost of three pencils at 5 each, but it prints 10. Find and fix the bug: pencil = 5 then cost = pencil + pencil then print("Cost:", cost).
Trade-offs
- ↔
Exactness is the price of speed. A computer can follow billions of steps a second, but only because every step is exact. You trade the flexibility of human language for reliability and speed.
- ↔
Errors that stop the program are kinder than silent wrong answers. A crash tells you where to look. A wrong total can go unnoticed for months. This is why later phases teach you to check inputs and write tests.
Done when you can
Done when you can explain what a program is using the recipe analogy.
Done when you can point to the input, the processing and the output in a small program.
Done when you can say what
print("...")does and run an example on this page.Done when you can explain why swapping two lines changes a program.
Done when you can tell a grammar mistake (Python refuses to run) from a bug that gives a wrong answer.