The shape of the lesson
By the end of the lesson, learners can
- Variables and constants: Run the totalling program in the lab one line at a time.
- Five data types: Choose the data type from what the data is and what the program will do with it.
- Input, output and sequence: INPUT stores a value typed by the user in a variable; OUTPUT displays values.
- Variable: named memory location; its value can change while the program runs.
- Constant: named value that cannot change while the program runs; declared with CONSTANT and a literal.
- Data types: INTEGER, REAL, CHAR, STRING, BOOLEAN. Phone numbers are STRING.
- Sequence: work through statements in order, updating each variable as you go.
One picture every idea returns to
A variable is a named memory location that stores a value which can change while the program runs. A constant is a named value that cannot change while the program runs. In pseudocode you declare them with DECLARE Score : INTEGER and CONSTANT VatRate ← 0.2, and assign with the arrow ←. The five basic data types are INTEGER, REAL, CHAR, STRING and BOOLEAN. Statements run one after another in sequence, so their order matters.
Forty-five minutes, phase by phase
| Time | Phase | What happens in the room | Grouping |
|---|---|---|---|
| 0 to 5 min | Hook: predict | Open with the question in the title, Name it, type it, store it.. Every program stores data while it runs: a score, a price, a name. Put the figure on the board: it is the one picture every idea in the lesson returns to. | Whole class, then pairs |
| 5 to 13 min | Teach and check: Variables and constants | Run the totalling program in the lab one line at a time. Project tab 1 of the lab (Sequence, selection and iteration with a trace table) and let a student drive it while the class predicts. | Whole class, then pairs |
| 13 to 21 min | Teach and check: Five data types | Choose the data type from what the data is and what the program will do with it. Model the worked example Choosing data types on the board, one line at a time. Your turn: Which data type should store the price of a cinema ticket, 7.50? | Pairs |
| 21 to 30 min | Teach and check: Input, output and sequence | INPUT stores a value typed by the user in a variable; OUTPUT displays values. Model the worked example Dry run on the board, one line at a time. Your turn: What is output by A ← 3, A ← A * 4, B ← A - 2, OUTPUT B? | Think-Pair-Share |
| 30 to 36 min | Check | The four Stage 1 questions from the student lesson, answered on mini whiteboards or by show of fingers. Re-teach the one most get wrong. | Individual, then whole class |
| 36 to 43 min | Plenary | The exam-style questions from Stage 2, one at a time: thirty seconds alone, then a random call. The feedback lines in the key give the examiner's wording. | Individual, random call |
| 43 to 45 min | Exit and homework | Set the worksheet below (6 questions, 19 marks). Learners self-assess against the objectives before they leave. | Individual |
Protect the parts that carry the learning
The sequence carries about fifty minutes of material, so the lab is driven by one student while the class predicts rather than explored freely. Times are a guide.
Protected: the check at 30 minutes. It is the only individual read on whether the key idea landed, and it is not cut.
Cut first if the build overruns: the last check in Input, output and sequence, never the check or the plenary.
In a 60 minute block: run worksheet questions 1 to 3 in class as a Rally Coach set and model both the hardest worked example and its check live.
Think-Pair-Share
Pose the question, give thirty seconds of silent thinking, then a minute to compare with a partner before a few pairs share with the class. The silent minute is the part that cannot be cut.
The full structure, with its variations and the other twelve, is on the cooperative-learning page.
What to head off, and how
| Trap learners fall into | Teaching move that pre-empts it |
|---|---|
| "A constant never changes" is not enough on its own. | Say that its value cannot be changed while the program is running, and give a benefit: it only has to be updated in one place. |
| A phone number is a STRING, not an INTEGER: storing it as a number would lose the leading zero, and nobody adds or multiplies phone numbers. | Return to Five data types: ask a pair to state the correct version and show it on the lab before moving on. |
| OUTPUT "Total" displays the word Total; OUTPUT Total displays the value stored in the variable Total. | Check your quotation marks. |
Variables, constants and data types: worksheet
6 questions, 19 marks. Written in the style of the papers; no past paper question is reproduced.
Explain the difference between a variable and a constant.
A school stores these items for each student. Give the most suitable data type for each: (a) StudentName (b) Age (c) AverageMark, e.g. 67.5 (d) HasPaidTrip (e) FormLetter, e.g. 'C'.
Write pseudocode that declares a constant Pi with the value 3.142, inputs the radius of a circle, then calculates and outputs the area (Pi × radius2).
State the output of this pseudocode.
A ← 4 B ← 3 C ← A * B - 2 A ← C + A B ← A - B OUTPUT A, " ", B, " ", C
A programmer stores mobile phone numbers as INTEGER. Explain why STRING would be a better choice.
A student chooses the identifiers 2ndScore, Total Mark and OUTPUT. Explain why each one is not allowed.
Answer key and marking notes
- A variable is a named memory location whose value can change while the program is running.
- A constant is a named value that cannot be changed while the program is running.
- (a) STRING
- (b) INTEGER
- (c) REAL
- (d) BOOLEAN
- (e) CHAR
CONSTANT Pi ← 3.142DECLARE Radius : REALandDECLARE Area : REALINPUT RadiusArea ← Pi * Radius ^ 2thenOUTPUT Area(or OUTPUT with a message)
- C ← 4 * 3 - 2 = 10.
- A ← 10 + 4 = 14; B ← 14 - 3 = 11.
- Output: 14 11 10
- A number stored as an integer would lose its leading zero (and could not hold spaces or a + sign).
- No arithmetic is ever done on a phone number, so it does not need a numeric type.
- 2ndScore starts with a digit; an identifier must start with a letter.
- Total Mark contains a space; identifiers contain only letters and digits.
- OUTPUT is a keyword, and keywords must never be used as identifiers.
6 multiple-choice questions on this lesson
From the topic question bank. Assign them in the app for a marked score in your gradebook, or run the topic as a class game.
Which statement best describes a constant in a program?
- AA named value that cannot be changed while the program is running
- BA named memory location whose value can change while the program is running
- CA value that the user types in each time the program is run
- DA variable that must be declared on the first line of the program
A program stores a customer's telephone number, for example 07700 900123. Which data type is most suitable?
- ASTRING
- BINTEGER
- CREAL
- DCHAR
A club records, for each member, whether they have paid this year's fee. Which declaration is most suitable?
- A
DECLARE HasPaid : BOOLEAN - B
DECLARE HasPaid : CHAR - C
DECLARE HasPaid : STRING - D
CONSTANT HasPaid ← TRUE
What is output by this pseudocode?
A ← 4 B ← A + 3 A ← B * 2 B ← A - B OUTPUT A, " ", B
- A14 7
- B7 14
- C8 4
- D14 -7
X and Y are INTEGER variables holding different values. Which sequence of statements correctly swaps their values, using an extra variable Temp?
- A
Temp ← XthenX ← YthenY ← Temp - B
X ← YthenY ← XthenTemp ← X - C
Temp ← XthenY ← TempthenX ← Y - D
Temp ← YthenX ← YthenY ← Temp
This program is meant to add VAT to a price.
CONSTANT VatRate ← 0.2 DECLARE Price : REAL DECLARE Total : REAL INPUT Price VatRate ← 0.25 Total ← Price + Price * VatRate OUTPUT "Total to pay: ", TotalWhy will this program not be accepted?
- AIt tries to assign a new value to VatRate, which is a constant
- BPrice must be declared as an INTEGER because it is input
- CTotal must be given a value before it is used in the calculation
- DThe OUTPUT statement cannot mix text and a variable
Quiz key
A constant is given its value once, in the code, and that value cannot be changed while the program runs (it only has to be edited in one place if it ever needs updating). A named location whose value can change is a variable. A value typed in by the user is input, which is stored in a variable. Where a declaration appears does not make something a constant.
A telephone number is a STRING: it can start with 0 and contain a space, and nobody adds or multiplies phone numbers. As an INTEGER the leading zero would be lost and the space is not allowed. REAL is for numbers with a fractional part. CHAR holds only a single character.
Paid or not paid has exactly two states, so BOOLEAN (TRUE or FALSE) is the right type for a variable. CHAR or STRING could store 'Y' or "Yes" but allow meaningless values and are less suitable. A constant cannot be used because the value differs from member to member and changes when a member pays.
B becomes 4 + 3 = 7, then A becomes 7 * 2 = 14, then B becomes 14 - 7 = 7, so the output is 14 7. 7 14 prints the values the wrong way round. 8 4 ignores the order of the lines (using A = 4 when calculating A ← B * 2 as A * 2). 14 -7 works out B - A instead of A - B on the fourth line.
Saving X in Temp first means its value survives when X is overwritten by Y; Temp is then copied into Y. With X = 1, Y = 2 this gives X = 2, Y = 1. Writing X ← Y first destroys the original X, so both end up 2. Temp ← X, Y ← Temp, X ← Y copies X into Y and then back, so both end up 1. Saving Y instead of X leaves Y unchanged and both end up 2.
VatRate is declared with CONSTANT, so its value cannot be changed while the program runs; the line VatRate ← 0.25 is an error (if the rate changes, edit the CONSTANT line instead). A price can have pence, so REAL is right. Total is on the left of the arrow, so it is being given a value, not used. OUTPUT may list text and variables separated by commas.
What to project
The student lesson embeds these tabs. Open them full screen on the projector; every slider has a drag handle on the stage.
Slides for this lesson
A projectable deck for every pack is on the way. Until then, present the student lesson full screen: its sections, figure and lab tabs follow the same order as the plan above.