CoursePython from Scratch to Intermediate · Module 1: Getting Started · part 8 of 75
Part 8 · Module 1: Getting Started

Lesson 1: Your first program, a card for one book

14 min read·14 Oct 2026
Module 1 · Lesson 1 · About 30 minutes · Needs: nothing. A Google account and a web browser

The situation

It is Wednesday 14 October 2026 at Kettle and Page, a small café with a lending shelf called Booknook. Amira Haddad owns the café and runs the shelf. Her records are a paper notebook and a messy spreadsheet, and she cannot say quickly which books are out or who is late. Her first question is a small one: "Can the computer print a card for one book?" The book she picks is Frankenstein, which Jonah borrowed a month ago. By the end of this lesson you will have printed that card with your own first program.

A real case, first

Almost every programmer's first program prints one short greeting, and the habit has a documented start. Brian Kernighan used a "hello, world" example in tutorials he wrote at Bell Labs in the 1970s. Then, in 1978, Brian Kernighan and Dennis Ritchie published The C Programming Language. The first example program in that book prints the words "hello, world", and it became the traditional first program in almost every language since.

Such a tiny program proves the whole chain works: you write an instruction, the computer runs it, and you see the result. Everything else is built on that one round trip.

What you will be able to do

  • Explain what a program is, in one sentence.
  • Open a Google Colab notebook and run a cell.
  • Use print to show text and numbers, and print Amira's shelf card.
  • Write a comment that explains why a line is there.
  • Read an error message from the last line up, and fix the mistake.

1. What a program is (Essential)

Before you write code, it helps to know what you are making. A program is not magic: it is a list of instructions, followed exactly.

Instructions exact, in order Computer follows them Result a printed card A PROGRAM
A program is a list of exact instructions (blue, your code); the computer follows them and produces a result (green).

A program is a list of instructions written so exactly that a computer can follow them without asking anything. A recipe is close: "boil the kettle, warm the pot, add the tea". The difference is that a cook fills gaps with common sense, and a computer has none. It does exactly what the words say, in the order they are written.

YOUR CODE OUTPUT 1 print("Kettle and Page opens") Kettle and Page opens 2 print("Amira checks ...") Amira checks ... 3 print("Jonah still has ...") Jonah still has ...
Python runs one line at a time from the top down, so the output comes out in the same order as the lines.

The language you write the instructions in is called a programming language. This course uses Python. Python reads your instructions from the top line down, one at a time. Here is a program of three lines. Each line tells Python to show one piece of text.

python
print("Kettle and Page opens")
print("Amira checks the Booknook shelf")
print("Jonah still has Frankenstein")

Code walkthrough

  • Each line is one instruction. print means "show this on the screen"; section 4 explains it properly.
  • Python runs line 1, then 2, then 3, so the output comes out in that order.

Output

text
Kettle and Page opens
Amira checks the Booknook shelf
Jonah still has Frankenstein
Amira: "print a card" which book? which words? in what order? A program 1. the heading 2. the title 3. author and year 4. the loan
A request a person understands (amber, uncertain) leaves gaps; a program spells out every line, in order.

"Print a card for one book" is clear to a person, not to a computer: which book, which words, in what order? Programming is mostly turning a request like Amira's into instructions with no gaps.

2. Meet the Booknook shelf (Essential)

Every lesson works on the same small project, so you never learn a new setting. Knowing its numbers now makes later code readable at a glance.

BOOKNOOK IN NUMBERS (SIMULATED DATA) books 24 24 titles, 27 copies members 6 M01 to M06 loans 40 14 Sep to 13 Oct
Booknook is small enough to hold in your head: 24 books (27 copies), 6 members and 40 loans.

Booknook is made up, and so are its people and loans; the books are real old titles that anyone may copy. The shelf holds 24 books, 27 copies in all, because three popular titles have two copies. Six members borrow them, and the records hold 40 loans between 14 September and 13 October 2026.

THE FOUR SHELF RULES 14 days Loan period 20p a day Late fee 300p (£3.00) Fee cap 3 books Limit
The shelf has four rules, and every later lesson uses the same four numbers.

The shelf has four rules. A loan lasts 14 days. A late book costs 20 pence for each day after it is due. The fee for one loan stops at 300 pence, which is £3.00. And nobody may have more than 3 books out at once. Fees go into the café's charity jar.

python
print("Booknook rules")
print("Loan period: 14 days")
print("Late fee: 20 pence a day")
print("Fee cap: 300 pence")
print("Limit: 3 books per member")

Code walkthrough

  • Five instructions, five lines of output: the same print, different text.
  • Money is written in whole pence, never pounds with a decimal point. Module 2 shows why.

Output

text
Booknook rules
Loan period: 14 days
Late fee: 20 pence a day
Fee cap: 300 pence
Limit: 3 books per member
LOAN L04: JONAH, FRANKENSTEIN Mon 14 Sep borrowed Mon 28 Sep due back Wed 14 Oct today 16 days late 14 days
Jonah's loan of Frankenstein was due on 28 September; today, 14 October, it is 16 days late (red, a problem).

The book Amira chose is the one this lesson follows. Jonah borrowed Frankenstein, by Mary Shelley, first published in 1818, on Monday 14 September 2026. The loan is numbered L04. It was due back on Monday 28 September. Today, 14 October, it is 16 days late, past the point where the fee stops growing.

THE CARD GROWS, MODULE BY MODULE M1 a card M2 a fee M4 12 loans M7 real dates M8 files M11 a command
Today's card (blue) is step one; later modules (grey) add fees, loops, dates, files and a command.

Today the card is a few lines of text. Each module makes it more capable, ending with one command Amira runs each morning.

3. Opening a Colab notebook and running a cell (Essential)

You need somewhere to run Python, and the quickest is a website. With nothing to install, you can start in two minutes on any computer with a browser.

A cell in your browser Python runs it on Google's computer The output under the cell nothing to install on your computer
In Colab you type in the browser; Google's computer runs the cell and sends the output back underneath.

Google Colab is a free website that runs Python for you. You type code into a box on the page, and a computer at Google runs it and sends back the result. Go to colab.research.google.com, sign in with a Google account, and choose New notebook. The page you get is called a notebook.

print("Hello from the Booknook shelf") Hello from the Booknook shelf [1] code output run button run counter [1] appears after a run
A code cell: press the run button or Shift+Enter, and the output appears underneath with a run counter beside it.

A notebook is made of boxes called cells. A code cell has a play button on its left and room for code on its right. Click in the empty cell, type the line below, and press Shift+Enter (hold Shift, then press Enter). The result appears under the cell. The first run takes a few seconds while Colab connects.

python
print("Hello from the Booknook shelf")

Code walkthrough

  • One line, the whole program: your "hello, world".
  • Shift+Enter runs the cell and moves to the next one.

Output

text
Hello from the Booknook shelf
ON THE PAGE THE ORDER COLAB USED [2] print("A") [1] print("B") [3] print("C") [1] ran, printed B [2] ran, printed A [3] ran, printed C
The run counters show the order you ran the cells, and Colab follows that order, not the order on the page.

After a cell runs, a number in square brackets appears to its left, such as [1]. It is the run counter: the order in which you ran cells. Colab follows that order, not the order cells sit on the page. If things look odd, choose Runtime, then Restart session and run all. The course setup page has more detail.

4. print and your first output (Essential)

Almost every program in this course ends by showing something, so print is the first tool to know well. It is also how you check what your code does.

print("Frankenstein") function name brackets quotation marks: start and end of text the string
print("Frankenstein"): the function name, round brackets around what to show, and a string inside quotation marks.

print is a function: a named action that Python already knows how to do. You use it by writing its name followed by round brackets, and you put what to show inside the brackets. Text goes inside quotation marks. The quotation marks mark where the text starts and stops; they are not printed. A piece of text in quotation marks is called a string.

python
print("Frankenstein")
print('Mary Shelley')
print("Jonah's loan")

Code walkthrough

  • "Frankenstein" is a string in double quotation marks.
  • 'Mary Shelley' uses single quotation marks. Python accepts either, as long as both ends match.
  • "Jonah's loan" uses double marks on the outside, so the apostrophe inside is just a letter.

Output

text
Frankenstein
Mary Shelley
Jonah's loan
FOUR VALUES, ONE LINE "Frankenstein" "by" "Mary Shelley" 1818 , , , Frankenstein by Mary Shelley 1818 print puts one space between values
Values separated by commas print on one line, with a single space between each; the commas are not printed.

You can give print several values at once by separating them with commas. Python prints them on one line with a single space between each. A number such as 1818 needs no quotation marks. An empty print(), with nothing inside the brackets, prints a blank line.

python
print("Frankenstein", "by", "Mary Shelley", 1818)
print()
print("Loan", "L04", "due back", "Monday 28 September 2026")

Code walkthrough

  • The commas separate four values; the spaces come from print.
  • 1818 has no quotation marks, so it is a number. It looks the same when printed.
  • print() prints the empty line in the output.

Output

text
Frankenstein by Mary Shelley 1818

Loan L04 due back Monday 28 September 2026
print(20 * 15) print("20 * 15") a calculation: worked out text: printed as written 300 20 * 15
Without quotation marks Python works the sum out (15 days at 20p is the 300p cap); with them it prints the text unchanged.

Numbers and text behave differently even when they print alike. Without quotation marks, Python works a sum out before printing it. The * symbol means multiply. With quotation marks, the same characters are just text, printed exactly as written. This sum is the fee cap: 15 days at 20 pence reaches 300.

python
print(20 * 15)
print("20 * 15")

Code walkthrough

  • 20 * 15 without quotes is a calculation, so print shows its answer, 300.
  • "20 * 15" is a string, so print shows those seven characters unchanged.

Output

text
300
20 * 15
BOOKNOOK SHELF CARD Frankenstein by Mary Shelley, 1818 Loan L04: Jonah, borrowed Monday 14 September 2026 Due back Monday 28 September 2026 (blank line)
Six print calls make Amira's first shelf card: heading, title, author and year, the loan, the due date and a blank line.

Now you have everything Amira asked for. The card is six print lines: a heading, the book, author and year, the loan, the due date and a blank line.

python
print("BOOKNOOK SHELF CARD")
print("Frankenstein")
print("by Mary Shelley, 1818")
print("Loan L04: Jonah, borrowed Monday 14 September 2026")
print("Due back Monday 28 September 2026")
print()

Code walkthrough

  • The comma in "by Mary Shelley, 1818" is inside the quotation marks, so it is part of the text and is printed. Commas outside quotation marks separate values.
  • The last print() adds a blank line after the card.

Output

text
BOOKNOOK SHELF CARD
Frankenstein
by Mary Shelley, 1818
Loan L04: Jonah, borrowed Monday 14 September 2026
Due back Monday 28 September 2026

5. Comments that explain why (Essential)

Code says what the computer does, not why you wrote it that way, and in a month you will have forgotten. Comments leave that note for the next reader.

print("Due back Monday 28 Sep") # loans last 14 days runs skipped by Python from # to the end of the line
Everything from # to the end of the line is a comment (grey): Python skips it and runs the code before it (blue).

A comment is a note in your code that Python ignores. It starts with the hash symbol, #. Everything from the # to the end of the line is skipped. A comment can sit on its own line or at the end of a line of code. Putting # at the start of a line of code switches that line off without deleting it.

python
# Amira asked for this card on Wednesday 14 October 2026
print("BOOKNOOK SHELF CARD")
print("Frankenstein")
print("Due back Monday 28 September 2026")   # loans last 14 days
# print("Overdue")   switched off until we can work it out

Code walkthrough

  • Line 1 is a comment on its own line. Nothing is printed for it.
  • Line 4 has a comment after the code. The print runs; the part from # onwards is skipped.
  • Line 5 starts with #, so the whole line, print included, is skipped. "Overdue" is not printed.

Output

text
BOOKNOOK SHELF CARD
Frankenstein
Due back Monday 28 September 2026
says what: adds nothing says why: worth keeping # print the due date print("Due back ...") # loans last 14 days print("Due back ...")
A comment that repeats the code (red) adds nothing; one that says why (green) helps the next reader.

A good comment says why, not what. # print the title adds nothing: the code already says it. # loans last 14 days tells a reader where the date came from. Write the comment you would want in a month's time.

6. Reading your first error message (Essential)

Everyone who writes code makes mistakes every day. Errors are not a sign you are bad at this: they are Python pointing at the exact problem, if you know where to look.

File "<cell>", line 2 where print("Frankenstein) the line ^ the spot SyntaxError: unterminated string ... what went wrong
An error message says where, shows the line, points at the spot, and ends with the most useful line: the kind of error and what went wrong (red).

When Python cannot follow an instruction, it stops and prints an error message instead of output. The message has a few lines. They say where the problem is (which line), show that line, and point at it. The most useful line is the last one: it names the kind of error, then says in words what went wrong.

1. last line what kind, what 2. line number where 3. the caret ^ which spot
Read an error message from the bottom up: the last line first (red), then the line number, then the caret.

So read the error message from the bottom up. The last line says what kind of mistake it is. The line number above it says where. The small arrows or carets, ^, point at the spot on that line. Then fix one thing, and run the cell again.

Break it: drop a quotation mark

Here is the card with one character missing. It is broken on purpose, so it is shown as text: type it into a new cell and run it.

text
print("BOOKNOOK SHELF CARD")
print("Frankenstein)

The message below is from the course's Python 3.12. Colab shows the same last line, with colour and a different cell name at the top.

text
  File "<cell>", line 2
    print("Frankenstein)
          ^
SyntaxError: unterminated string literal (detected at line 2)

Read it from the bottom. A SyntaxError means Python could not understand how the code is written. "Unterminated string literal" means a piece of text was started and never finished: the closing quotation mark after Frankenstein is missing. The caret points at where that text began. Nothing was printed, not even the heading on line 1.

Break it: a capital letter

This time every quotation mark is there, but print on line 2 has a capital P.

text
print("BOOKNOOK SHELF CARD")
Print("Frankenstein")
text
BOOKNOOK SHELF CARD
Traceback (most recent call last):
  File "<cell>", line 2, in <module>
    Print("Frankenstein")
    ^^^^^
NameError: name 'Print' is not defined. Did you mean: 'print'?

The last line says NameError: Python met a name it does not know. Capital and small letters count as different, so Print is not print. Python 3.12 even suggests the fix; Colab may not show that hint, but the rest of the last line is the same.

SyntaxError NameError found before running found while running line 1: heading line 2: the mistake line 1: heading line 2: the mistake output: nothing at all output: the heading, then the error
A SyntaxError stops the cell before any line runs (grey, never ran); a NameError lets line 1 run (green) and stops at line 2 (red).

The two errors fail at different moments. Python reads the whole cell before running it, so a SyntaxError stops everything and not even line 1 prints. A NameError is found while running, so line 1 has already printed when line 2 fails.

Run Read last line Change one thing Run again still an error? go round again
Fixing is a loop: run, read the last line, change one thing (amber, not yet proven), and run again.

The fix is always the same: read the last line, go to the line it names, change one thing, and run again. Change one thing at a time, or you will not know which change was the fix.

In production

Professional programmers read error messages all day. Python 3.10 (2021) listed "Better error messages" among its new features, and the "Did you mean" hint comes from that work. Teams also keep comments honest: Python's style guide, PEP 8, says "comments that contradict the code are worse than no comments" and asks that comments be updated when the code changes. At any size the habits are the same: read the last line first, and write comments that stay true.

What you added to the Booknook shelf

  • A first program: six print lines that show Amira's card for Frankenstein, loan L04.
  • The four shelf rules printed as text: 14 days, 20 pence a day, 300 pence cap, 3 books.
  • Comments that say why the due date is what it is.
  • A habit: read an error message from its last line up.

Check yourself

  1. What does Python do with the lines of a program, and in what order?

It runs them one at a time, from the top line down. The output appears in the same order as the lines that print it.

  1. What does print("Loan", "L04") show, and why is there a space in the output?

It shows Loan L04. The comma separates two values, and print puts one space between values. The comma itself is not printed.

  1. What is the difference between print(20 * 15) and print("20 * 15")?

The first is a calculation, so it prints 300. The second is text in quotation marks, so it prints 20 * 15 exactly as written.

  1. You run a cell and see NameError: name 'prnt' is not defined. Which line of the message do you read first, and what is wrong?

The last line, which is the one quoted. Python does not know the name prnt: it is a typing mistake for print.

Exercise

Priya has The Adventures of Sherlock Holmes by Arthur Conan Doyle, first published in 1892. Her loan is L24, borrowed on Thursday 1 October 2026 and due back on Thursday 15 October 2026. Write a cell that prints her shelf card in the same shape as Jonah's, with one comment that says why the due date is 15 October.

Check: run your cell. Your output must match these five lines exactly, capital letters and commas included, followed by a blank line:

text
BOOKNOOK SHELF CARD
The Adventures of Sherlock Holmes
by Arthur Conan Doyle, 1892
Loan L24: Priya, borrowed Thursday 1 October 2026
Due back Thursday 15 October 2026

If a line differs, compare it one character at a time. If you see an error, read its last line first.

python
print("BOOKNOOK SHELF CARD")
print("The Adventures of Sherlock Holmes")
print("by Arthur Conan Doyle, 1892")
print("Loan L24: Priya, borrowed Thursday 1 October 2026")
print("Due back Thursday 15 October 2026")   # 1 October plus the 14-day loan
print()

Code walkthrough

  • The same six lines as Jonah's card, with Priya's book and dates in the text.
  • The comment says where 15 October comes from: the borrow date plus the 14-day loan period.

Key terms

TermMeaning
programA list of instructions exact enough for a computer to follow
Google ColabA free website that runs Python code in your browser
cellOne box in a notebook; a code cell holds code and shows its output underneath
run counterThe number in square brackets beside a cell: the order cells were run in
functionA named action Python can do, used with round brackets, such as print(...)
stringA piece of text inside quotation marks
commentA note after # that Python ignores
error messageWhat Python prints when it cannot follow an instruction; read the last line first
SyntaxErrorAn error in how the code is written, found before anything runs
NameErrorPython met a name it does not know, often a spelling or capital-letter slip

Sources

  • Brian W. Kernighan and Dennis M. Ritchie, The C Programming Language, Prentice Hall, 1978. The first example program prints "hello, world". (No link: a printed book.)
  • Python Software Foundation, "The Python Tutorial", Python 3.12 documentation. https://docs.python.org/3.12/tutorial/
  • Python Software Foundation, "Built-in Functions: print", Python 3.12 documentation. https://docs.python.org/3.12/library/functions.html#print
  • Python Software Foundation, "Errors and Exceptions", The Python Tutorial, Python 3.12 documentation. https://docs.python.org/3.12/tutorial/errors.html
  • Python Software Foundation, "What's New In Python 3.10", section "Better error messages", 2021. https://docs.python.org/3/whatsnew/3.10.html
  • Guido van Rossum, Barry Warsaw and Alyssa Coghlan, "PEP 8: Style Guide for Python Code", 2001, section "Comments". https://peps.python.org/pep-0008/