- Understand what a variable is and why programs use them
- Know Python's basic data types: integer, float, string, boolean
- Use arithmetic operators to calculate and store values
- I can create a variable and assign it a value
- I can identify the data type of a value
- I can write a program that performs a calculation using variables
Answer before the lesson begins. These check prior knowledge — it's fine if you're unsure.
1. Which of these is a whole number, with no decimal point?
2. What is 10 divided by 3, written as a decimal (roughly)?
3. True or false: the word "Hello" is a whole number.
Key vocabulary
int. Example: 12.float. Example: 3.5.str. Example: "Hello".True or False. In Python: bool.= symbol, e.g. age = 13.+ for addition.Variables, Data Types and Simple Arithmetic
What is a variable?
423.5"hello"True or FalseA variable is a named container that stores a value while your program is running. Instead of writing the same number or piece of text over and over, you give it a name and refer to that name instead. In Python, you create a variable by choosing a name and using the = symbol to store a value in it — this is called assignment.
For example, age = 13 creates a variable called age and stores the value 13 inside it. From that point on, wherever your program uses age, it means "whatever value is currently stored there." Variables are called that because the value can change — later in the same program you could write age = 14 and the old value would be replaced.
Variable names must follow some rules: they cannot start with a number, cannot contain spaces, and cannot use most punctuation. Good variable names describe what they store — total_cost is much clearer than x.
Data types in Python
Every value in Python has a data type, which tells the program what kind of value it is and what can be done with it. The four data types you need for N3/N4 are:
| Data type | Python name | Example | Used for |
|---|---|---|---|
| Integer | int | 12 | Whole numbers — counts, ages, scores |
| Float (real) | float | 3.5 | Numbers with decimal places — prices, measurements |
| String | str | "Hello" | Text — names, messages, labels |
| Boolean | bool | True | Yes/no, on/off type values |
You can check a value's data type using Python's built-in type() function, for example type(age). Choosing the right data type matters: a number written with quotation marks around it, like "12", is a string, not an integer — even though it looks like a number. Python will not let you do arithmetic with it until it is converted.
Arithmetic operators
Python uses symbols called operators to perform calculations on numbers stored in variables:
| Operator | Meaning | Example | Result |
|---|---|---|---|
+ | Addition | 7 + 3 | 10 |
- | Subtraction | 7 - 3 | 4 |
* | Multiplication | 7 * 3 | 21 |
/ | Division | 7 / 2 | 3.5 |
// | Floor (whole-number) division | 7 // 2 | 3 |
% | Modulus (remainder) | 7 % 2 | 1 |
Notice that / always gives a float, even when the answer is a whole number, while // throws away anything after the decimal point. % is useful whenever you need to know what is "left over" — for example, checking whether a number is even by testing number % 2 == 0.
Order of operations
Python follows the same order of operations you use in maths (often remembered as BIDMAS/BODMAS): brackets first, then multiplication/division, then addition/subtraction. 2 + 3 * 4 evaluates to 14, not 20, because the multiplication happens first. Use brackets to force a different order: (2 + 3) * 4 evaluates to 20.
Worked examples
A program needs to store a pupil's age and display it.
age.age = 13. This creates the variable and stores 13 in it.print(age) outputs 13. Note there are no quotation marks around age in the print() line — that would print the letters a-g-e instead of the value stored inside it.A programmer isn't sure whether a value has been stored as a number or as text.
score = "45" — note the quotation marks.print(type(score)). Python outputs <class 'str'>, confirming this is a string, not a number, despite looking numeric.score needs to be used in a calculation, it must first be converted using int(score) or float(score).A program calculates the total cost of 3 items priced at £2.50 each.
price = 2.50 and quantity = 3 — two variables, one float and one integer.total = price * quantity stores the result of the calculation, 7.5, in a new variable called total.print(total) outputs 7.5. The calculation happens once, on the right-hand side of the =, before the result is stored.A recipe scales its ingredients based on how many people it serves. It uses rice_per_person = 200 (grams) and people = 4, then calculates total_rice = rice_per_person * people.
Answer the following:
- What data type is
rice_per_person? - What value will
total_ricehold after the calculation runs? - If
peoplehad instead been written aspeople = "4", what would go wrong when the program tried to calculatetotal_rice?
rice_per_personis an integer (int) — it is a whole number with no decimal point.total_ricewould hold800(200 × 4).- Python would raise an error, because
"4"is a string, not a number — you cannot multiply a number by a piece of text in Python. The program would need to convert it withint(people)first.
total = "10" creates a string, not an integer, even though it looks like a number. Arithmetic on it will fail until it is converted.print("Age: " + age) causes an error if age is an integer — Python cannot join text and numbers with + directly. Convert first with str(age), or separate with a comma: print("Age:", age).2total (starts with a number) or total cost (contains a space) will cause errors. Use total_cost instead./ and //. 7 / 2 gives 3.5, but 7 // 2 gives 3. Choosing the wrong one gives a technically-running program with the wrong answer, which is harder to spot than an error message.N4 pupils: it isn't enough to just use variables correctly — you need to be able to explain the purpose of the data type you chose for each variable in your evidence. Practise saying, out loud, "I used a float here because the value needs decimal places" rather than just writing the code.
Questions 1–5 are auto-checked. Questions 6–7 are self-marked — write your answer, then reveal the model answer to check your work. Questions 8–9 are practical tasks in IDLE.
1. Which data type would best store a pupil's exam mark out of 100? TYPE 1
2. What is the result of 7 // 2 in Python? TYPE 1
3. Which of these is a valid Python variable name? TYPE 1
4. What data type is the value True? TYPE 1
5. What is 10 % 3 in Python? TYPE 1
6. In your own words, explain what a variable is and give one example of why a program might need one. TYPE 2 N4
score to keep track of how many questions a pupil has answered correctly, updating it each time instead of storing a separate value for every question.7. A programmer wrote age = "13" instead of age = 13. Explain what data type this creates and why it could cause a problem later in the program. TYPE 2 N4
age = "13" creates a string, not an integer, because the value is inside quotation marks. This could cause a problem later if the program tries to use age in a calculation, such as adding 1 to it — Python cannot perform arithmetic directly on a string, so the program would raise an error unless age is first converted using int(age).8. Practical: In IDLE, create a new file called sdd1_arithmetic.py. Write a program that stores two numbers in variables, adds them together, and prints the result. Test it with 5 and 3, then with 12 and 8. Record your output below. TYPE 3
num1 = 5
num2 = 3
total = num1 + num2
print(total)Expected output:
8, then (after changing the values) 20.9. Practical: In sdd1_arithmetic.py, extend your program to also calculate and print the average of the two numbers. Test with the same values as Q8 and record your output. TYPE 3
average = total / 2
print(average)Expected output for 5 and 3: total
8, average 4.0. For 12 and 8: total 20, average 10.0. Note the average always shows as a float, since / always produces a decimal result.Suggested timing: 55 minutes. Warm up 5 min; notes 15 min; examples 10 min; now you try 5 min; task set 20 min.
Key misconception to address: pupils very often type numbers in quotation marks out of habit from other subjects, or because IDLE's input() always returns a string (which is covered next lesson) — reinforce the "quotation marks mean text" rule early and often.
Live demo suggestion: deliberately write print("Total: " + total) where total is an integer, run it live, and let pupils read the TypeError message before explaining it.
Extension idea (S5 / N5-bridging, non-assessed): introduce naming conventions used at N5 (e.g. constants in capitals) as a "look ahead," kept clearly separate from the assessed task set.
Assessment standards covered: N3 O2.1; N4 O1.2, O1.3, O2.2.