This mini-lesson covers the core of writing programs (in Python-style code): data types, variables & constants, the three programming constructs sequence, selection & iteration, operators, arrays/lists, subprograms, string manipulation and file handling.
Work through each screen, answer the questions (some code-reading, some calculations) and collect ⭐ stars. Press Start when you're ready.
Programming · data types
Data types
Every value has a data type that tells the computer how to store and use it:
Integer — a whole number, e.g. 42, -7.
Real / float — a number with a decimal point, e.g. 3.14.
Boolean — only True or False.
Character — a single symbol, e.g. 'A'.
String — a sequence of characters, e.g. "hello".
Watch out:"42" (in quotes) is a string, not an integer — you can't do arithmetic on it until you convert it with something like int("42"). Choosing the right type is called casting when you convert.
Quick check
Which data type?
?A variable stores whether a user is logged in: it is either True or False. Which data type is best?
Programming · variables & constants
Variables & constants
A variable is a named store whose value can change while the program runs, e.g. score = score + 1.
A constant is a named value that must not change, e.g. VAT = 0.20 or PI = 3.14159. Using a constant makes code clearer and easier to update.
price = 50 VAT = 0.2 # constant total = price + price * VAT# assignment uses =, and works right-hand-side first
Assignment:total = price + 10 means "work out the right-hand side, then store it in total". The = sign is assignment, not "equals" in the maths sense.
Programming · operators
Operators
Arithmetic: + − * /, plus ** (power), // (integer division / DIV) and % (remainder / MOD).
Common trap:= assigns a value; == tests whether two values are equal. Mixing them up is a classic bug.
Calculate
Your turn — remainder (MOD)
1What is the result of 23 % 4 (the remainder when 23 is divided by 4)?
Hint: 4 × 5 = 20, and 23 − 20 = 3.
Programming · the three constructs
Sequence, selection & iteration
Every program is built from three constructs:
Sequence — statements run in order, one after another.
Selection — choose a path using IF / ELIF / ELSE.
Iteration (loops) — repeat code. A FOR loop repeats a set number of times; a WHILE loop repeats while a condition is true (a condition-controlled loop).
total = 0 for i in range(1, 6): # i = 1,2,3,4,5 total = total + i print(total) # 15range(1, 6) counts 1 up to but NOT including 6.
FOR vs WHILE: use FOR when you know how many repeats; use WHILE when you repeat until something happens (e.g. until the user types "quit").
Trace it
Your turn — how many times?
2How many times does the body of this loop run: for i in range(0, 10)? (range(0, 10) gives 0 up to but not including 10.)
times
Hint: the values are 0,1,2,3,4,5,6,7,8,9 — count them.
Quick check
Read the code
?Given age = 17, what does this print? if age >= 18: print("adult") else: print("minor")
Programming · arrays & lists
Arrays & lists
An array (a list in Python) stores many values under one name. Each value has a position number called its index, starting at 0.
animals = ["cat","dog","fox","owl"] — the first item is index 0, so animals[2] is "fox".
Off-by-one trap: a list of 4 items has indexes 0 to 3. Asking for index 4 gives an out-of-range error.
Sort it
What data type is each value?
Tap a value, then tap its data type.
🔤 String
🔢 Integer
✅ Boolean
Calculate
Your turn — the last index
3A list scores holds 8 values. What is the index of the last item?
Hint: indexes start at 0, so 8 items run 0 to 7.
Programming · subprograms
Subprograms: functions & procedures
A subprogram is a named block of code you can call whenever you need it. This supports decomposition and avoids repeating code.
A functionreturns a value, e.g. area(w, h) returns w × h.
A procedure does a job but doesn't return a value (in Python both use def).
Values passed in are parameters/arguments; the answer sent back uses return.
def area(w, h): return w * h print(area(4, 5)) # 20area is a function: it takes parameters w and h and returns a value.
Benefits: subprograms make code easier to read, test and reuse, and let a team work on different parts.