Study Guide Instructor view
Variables, Data Types and Operators
Teaching notes for Lesson 5.3, with controls for presenting it.
Keep this page on your own screen. Share only the lesson window. The lesson window holds no teaching notes, so sharing it cannot show them.
Presenting
- Open the lesson in its own window and share that window, not this one.
- Use Next and Previous here, or the lesson’s own, to move through the lesson. Next reveals one thing at a time: the next idea, or the answer to the question on screen, then the next step. Previous takes the last reveal back. The line below says what is on screen and what Next will show.
- Reveal hints and answers when the class is ready, and reset a demonstration before using it again.
The controls need JavaScript and a browser that supports BroadcastChannel. Without them, open the lesson in presentation mode and use its own controls.
The two windows talk to each other only inside this browser, on this device. Nothing is sent to a server, and no account is needed. A second device (a phone or another tablet) cannot follow the lesson window yet.
Now on the lesson window
- On screen
- Next teaching point
Guidance for this point
Lesson plan
- Level
- Beginner
- Time
- About 75 minutes; the steps below add up to 75
Pupils begin with a game score that the computer must remember and change, and meet the variable, assignment, constant, data type, input and output, arithmetic operators including DIV and MOD, and the relational and logical operators in that order. Almost every idea is met first through a prediction or a trace, with the exact notation named afterwards. The biggest risks are reading the arrow as an equals sign, treating a number in quotes as a number, and mixing up DIV and MOD, so most of the board work is tracing.
Objectives
- Declare and use variables and constants, and explain what an assignment does
- Choose the correct data type (INTEGER, REAL, CHAR, STRING or BOOLEAN) for a value
- Use INPUT and OUTPUT, and explain why the order of instructions matters
- Work out the result of expressions using + - * / ^ DIV and MOD
- Work out the result of relational and logical expressions
- Trace a short program and write a short one of your own
Before the lesson
- Mini whiteboards, one per pupil, for predictions and for holding up trace answers.
- Draw a table on the board with columns Line carried out, Score, OUTPUT before the lesson; you will fill it in live at step 2.
- Have a box labelled Score and a sticky note on it as a prop: a sticky note you cross out and replace shows that assignment replaces the old value.
- Write the five data types and an example of each on a strip for the wall.
- Optional: a bag of 17 counters for the sharing problem in the arithmetic step.
Steps
Introduction Opening
On the lesson window now
On screen: the lesson’s title, module and number; Next adds its objectives and key terms, as the lesson page lists them; Next again begins the first step.
Objectives on screen
- Declare and use variables and constants, and explain what an assignment does
- Choose the correct data type (INTEGER, REAL, CHAR, STRING or BOOLEAN) for a value
- Use INPUT and OUTPUT, and explain why the order of instructions matters
- Work out the result of expressions using + - * / ^ DIV and MOD
- Work out the result of relational and logical expressions
- Trace a short program and write a short one of your own
Purpose: Pupils begin with a game score that the computer must remember and change, and meet the variable, assignment, constant, data type, input and output, arithmetic operators including DIV and MOD, and the relational and logical operators in that order. Almost every idea is met first through a prediction or a trace, with the exact notation named afterwards. The biggest risks are reading the arrow as an equals sign, treating a number in quotes as a number, and mixing up DIV and MOD, so most of the board work is tracing.
1. Remembering a score Think 4 min
On the lesson window now
Purpose: Pupils work out, from a game they can picture, that a program must read and change a remembered value, before the word variable is used.
Ask
- What must the computer be able to do with the score?
- What would you call the place where it is kept?
Responses to expect
- Show it and change it
- Some will say a box or a store
- A few will say the score is a number and stop there
Misconceptions to challenge
- A learner may believe: “The computer just knows the score.” Respond: Ask where the score lives between two coins. The computer has to put it somewhere and find it again by name.
Checking understanding: Ask pupils to hold up one finger for read and two for change; every answer should include both.
Depending on the answers
- If pupils only mention showing the score: ask what must happen to the remembered score when a coin is collected.
English as an additional language
- Check the words coin and score; show a coin counter on screen.
Discussion pause: Thirty seconds of silent thinking, then pairs agree on two things the computer does with the score.
In the lesson window
- Think it through: What must the computer be able to do with that remembered score? And what would you call the place where it is kept?
2. Variables and assignment Predict 10 min
On the lesson window now
Purpose: Pupils predict a four-line program, then trace it, so that the rule of assignment (right-hand side first, then store) is built from a case where Score appears on both sides.
Ask
- What does this program output, and what does line 2 do?
- What is in Score after line 1? After line 2? After line 3?
- After Total ← 5, Total ← Total * 2, Total ← Total + 1: what does Total hold?
Responses to expect
- 20
- Some say the second line is impossible because Score cannot equal Score + 10
- 11 for the three-line check, though a few say 16
Misconceptions to challenge
- A learner may believe: “Score ← Score + 10 is impossible, like an equation.” Respond: It is an instruction, not an equation: take what Score holds, add 10, store the answer back.
- A learner may believe: “The variable keeps all its old values.” Respond: Each assignment replaces the old value; cross out the old sticky note and write the new one.
- A learner may believe: “An arrow can point either way.” Respond: The arrow points from the value to the variable that stores it; 5 ← Score means nothing.
- A learner may believe: “OUTPUT changes the variable.” Respond: Showing a value does not change it: the Score cell stays empty on that row.
On the board or with the pen
- Fill the trace table live: write 0 in Score, cross it out and write 10, cross that out and write 20, then write 20 in the OUTPUT column on the last row.
Checking understanding: The three-lines question: 6 means the second line was ignored, 10 means the last was missed, 16 means the values were added together; each wrong option points to a different slip.
Depending on the answers
- If many pupils answer 16: trace again on the board with a crossed-out note and ask what happened to 5 when 10 was stored.
- If the class traces easily: ask: what would Total hold if lines 2 and 3 were swapped? Compare 11 and 12.
Support
- Provide the trace table partly filled, with only the Total column to complete.
English as an additional language
- Check the words stores, replaces and right-hand side; show arrows on the board.
In the lesson window
- Think it through: Predict what this program outputs, and explain what the second line does. Note that Score appears on both sides of the arrow.
- Check your understanding: After these three lines have run, what does Total hold? Total ← 5, then Total ← Total * 2, then Total ← Total + 1.
3. Constants, declarations and names Discover 8 min
On the lesson window now
Purpose: Pupils work out the cost of typing 10 in forty places before they meet CONSTANT, DECLARE and the naming rules.
Ask
- What problem will the designers have, and how could the program avoid it?
- Which of these is an acceptable name?
- Why is a constant better than a bare 10?
Responses to expect
- Missing one place gives inconsistent points
- Give the value a name once
- TotalToPay is the only acceptable name
Misconceptions to challenge
- A learner may believe: “A constant is just a variable you promise not to change.” Respond: A constant's value is fixed by the program itself: CONSTANT PointsPerCoin ← 10 must be a plain value, not a calculation.
- A learner may believe: “Total_score is a good name because it is readable.” Respond: Cambridge names have no underscores or spaces and start with a capital; each new word has a capital.
- A learner may believe: “A constant makes the program run faster.” Respond: Speed is not the point; one change updates every use and the name explains the number.
- A learner may believe: “A constant can be changed by the player.” Respond: A constant is not changed while the program runs; the player changes variables like Score.
On the board or with the pen
- Write 10 forty times as a short column, then replace it with PointsPerCoin.
Checking understanding: The two checks: valid-name probes space, leading digit and underscore; why-constant probes speed and who changes it.
Depending on the answers
- If pupils choose total_score: ask them to find the two Cambridge rules it breaks, the underscore and the lower-case start.
Stretch
- What value would you make a constant in a school timetable program, and what would you leave as a variable?
In the lesson window
- Think it through: What problem will the designers have, and how could the program have been written to avoid it?
- Check your understanding: Which of these is an acceptable identifier in Cambridge pseudocode?
- Check your understanding: Why is a constant such as PointsPerCoin better than typing 10 wherever the score changes?
4. Kinds of value Discover 10 min
On the lesson window now
Purpose: Pupils sort ten values into groups before the five data types are named, so that the type is understood as what a program can do with a value. The phone-number question tests choosing a type from use, not from appearance.
Ask
- How many groups did you make, and what would you call each?
- Is 42 the same kind of thing as "42"?
- A phone number such as 07700 900123: which data type, and why?
Responses to expect
- Whole numbers, decimals, text, single characters, true or false
- Quotes make it text
- STRING, because the leading 0 must be kept
Misconceptions to challenge
- A learner may believe: “A number in quotation marks is still a number.” Respond: It is text: two characters. Ask what the computer would do if you asked it to add "42" and "8".
- A learner may believe: “Anything made of digits is an INTEGER.” Respond: Choose the type from how the value is used. A phone number is never added, and its leading 0 would vanish in an INTEGER.
- A learner may believe: “0.0 and -4.0 are integers because they are whole.” Respond: A REAL is written with a digit on both sides of the point; 0.0 is REAL.
- A learner may believe: “A CHAR and a STRING of one letter are the same.” Respond: A CHAR is one character in single quotes; a STRING is in double quotes and can be any length, including empty.
On the board or with the pen
- Draw five columns headed with the types and sort the ten values as pupils call them out; put "42" and 42 in different columns.
Checking understanding: The phone-number question has four options: INTEGER and REAL show which pupils pick a number type from appearance, BOOLEAN catches pupils who read valid as the answer. The type table checks all five types without help.
Depending on the answers
- If pupils choose INTEGER for the phone number: ask what happens to a leading 0 in a whole number, and whether anyone adds phone numbers.
- If the table is filled in quickly: ask them to name one value for each type from a game of their own.
Support
- Give the five type names on a card and ask pupils to match each value with the card.
English as an additional language
- Teach character as one letter, digit or symbol; show the single and double quotes on the board.
In the lesson window
- Think it through: Sort these ten values into groups of the same kind of thing. How many groups do you make, and what would you call each?
- Check your understanding: A school office stores each pupil’s phone number, such as 07700 900123, in a variable. Which data type should it use?
5. Input, output and sequence Predict 9 min
On the lesson window now
Purpose: Pupils predict the screen output of a short input-and-output program, trace it, and see that a change of line order changes the result.
Ask
- The user types Maya, then 12. What is everything on the screen, in order?
- What is Age when the last line runs?
- Swap the last two lines of the shop program: what is Price now?
Responses to expect
- Three lines, ending Maya will be 13 next year
- Some forget the +1 or add spaces
- 14 for the swapped program, though a few say 15 or 16
Misconceptions to challenge
- A learner may believe: “OUTPUT with commas puts spaces between the pieces.” Respond: The pieces are joined with nothing between them, so the spaces are inside the quotation marks.
- A learner may believe: “Quotation marks are shown on the screen.” Respond: They mark the start and end of the text; the screen shows the text only.
- A learner may believe: “The same instructions always give the same answer.” Respond: Work the swapped order: 8 - 1 is 7, doubled is 14, while 8 doubled is 16, minus 1 is 15.
On the board or with the pen
- Run the trace table live: write the six lines and the three column headings, and fill in Name, Age and OUTPUT as pupils call them out. Then rework the shop program in both orders in two columns.
Checking understanding: The reorder question has one slip in each wrong answer: ignoring the order, assuming multiplication is larger, or the right operations in the wrong order.
Depending on the answers
- If pupils write Maya will be 12 next year: ask which line changes Age, and trace it again.
- If pupils choose 15 for the swapped program: ask them to work it line by line on the board with each value written down.
Stretch
- Change the greeting program so that it shows the age next year, but the stored Age stays as typed. What do you need?
English as an additional language
- Check sequence as in order, one after another.
In the lesson window
- Think it through: A user types Maya and then 12. Write down everything the program shows on the screen, in order.
- Apply it: A shop program runs: Price ← 8, then Price ← Price * 2, then Price ← Price - 1, giving 15. A programmer swaps the last two lines, so the order is Price ← 8, Price ← Price - 1, Price ← Price * 2. What is Price at the end?
6. Arithmetic operators Discover 12 min
On the lesson window now
Purpose: Pupils share 17 sweets among 5 children to meet whole number and remainder before DIV and MOD are named; then use them for minutes into hours and for testing even numbers.
Ask
- How many sweets does each child get, and how many are left over?
- Which expression gives the number of whole bonus stars for 237 points?
- How do you test that a number is even?
Responses to expect
- 3 each, 2 left
- DIV(237, 50) is 4, not MOD and not 237 / 50
- MOD(Number, 2) = 0
Misconceptions to challenge
- A learner may believe: “DIV and / are the same.” Respond: / keeps the fraction (4.74); DIV counts how many whole times (4).
- A learner may believe: “MOD gives the answer to the division.” Respond: MOD gives only what is left over: 237 MOD 50 is 37.
- A learner may believe: “DIV(Number, 2) = 0 tests for even.” Respond: DIV(Number, 2) is the number of whole twos; it is 0 only for 0 and 1. Ask what should be zero for an even number: the remainder.
- A learner may believe: “14 + 3 * 2 is 34 because you work left to right.” Respond: Multiplication comes first; brackets change the order: (14 + 3) * 2 is 34.
On the board or with the pen
- Write 17 counters in groups of 5 on the board, draw 3 groups and 2 left, and label DIV and MOD. Then work 130 minutes as 2 hours 10 minutes, with a check: 120 + 10 = 130.
What learners should notice
- The check step in the worked example rebuilds the original number, a habit pupils can reuse.
Checking understanding: The even-number question has one wrong option that pupils pick if they think a whole division answer is 0; the arithmetic table checks brackets and powers.
Depending on the answers
- If pupils choose MOD for the star question: ask what MOD(237, 50) is and what it counts, then what question the star count needs answered.
- If pupils are secure with DIV and MOD: ask: what do DIV(7, 2) and MOD(7, 2) give, and how could you check them together?
Support
- Offer a worked line for DIV(23, 4): 4 goes into 23 five times (20), remainder 3.
Stretch
- How could MOD tell you whether a year is divisible by 4?
English as an additional language
- Check remainder, whole number and left over; use real counters.
In the lesson window
- Think it through: 17 sweets are shared out equally between 5 children, and nobody may be given a part of a sweet. How many does each child get, and how many are left over?
- Check your understanding: A game gives one bonus star for every 50 points. A player has 237 points. Which expression gives the number of whole stars?
- Check your understanding: A program must test whether a whole number, Number, is even. Which condition does it use?
7. Comparing values and combining tests Explain 9 min
On the lesson window now
Purpose: Pupils build a range rule from two comparisons before AND is named, link it to the logic gates, and meet the incomplete-test error in Sam's condition.
Ask
- A visitor is 14 and the ride is for 12 to 18: how would you write the rule with two comparisons?
- What is wrong with Age >= 12 AND <= 18?
- With Age 14 and HasTicket TRUE, is NOT HasTicket TRUE or FALSE?
Responses to expect
- Age >= 12 AND Age <= 18
- Nothing is on the left of <= 18
- FALSE
Misconceptions to challenge
- A learner may believe: “12 <= Age <= 18 is a valid condition.” Respond: Each side of AND must be a complete test. Write Age on both sides.
- A learner may believe: “OR means one or the other but not both.” Respond: OR is TRUE if at least one side is TRUE; both TRUE also gives TRUE, as in the OR gate.
- A learner may believe: “NOT HasTicket is TRUE because HasTicket is true.” Respond: NOT turns TRUE into FALSE; ask for the value after NOT.
On the board or with the pen
- Write Age >= 12 AND Age <= 18 and draw the two tests as two separate boxes joined by AND; cross out Sam's second test with the missing Age.
Follow-up questions
- Which values of Age make Age < 12 OR Age > 65 TRUE?
Checking understanding: The Sam question: the first option (the second test continues the first) diagnoses reading AND as plain English.
Depending on the answers
- If pupils think Sam's condition is correct: ask them to work out whether <= 18 alone is TRUE or FALSE; it has no value to compare.
- If the condition table is done quickly: ask them to write one condition of their own that is TRUE for Age 14 and one that is FALSE.
Support
- Provide the condition table with the comparisons already worked, so only AND, OR and NOT remain.
English as an additional language
- Check at least and at most; read each comparison aloud as a sentence.
In the lesson window
- Think it through: A theme-park ride is for visitors who are at least 12 and at most 18 years old. A visitor is 14. Is the visitor allowed on? Write the rule using a comparison for each end of the range.
- Apply it: Sam writes the condition for the ride as: Age >= 12 AND <= 18. What is wrong with it?
8. A complete program Apply 8 min
On the lesson window now
Purpose: Pupils trace a whole short program with a constant, DIV and MOD, then write one of their own, justifying a REAL.
Ask
- A pupil buys 4 snacks: what does the program output?
- Write a program that inputs two marks and outputs their average. Which type is Average, and why?
Responses to expect
- 3 pounds and 40 pence
- REAL, because the average can have a fractional part
- A few forget the brackets
Misconceptions to challenge
- A learner may believe: “The output is 340 pounds and 0 pence.” Respond: 340 is the total in pence; DIV(340, 100) gives the pounds.
- A learner may believe: “MarkOne + MarkTwo / 2 is the average.” Respond: Division comes first; only MarkTwo is halved. Try marks of 15 and 18: the brackets give 16.5.
- A learner may believe: “The average of whole marks is a whole number.” Respond: Show 15 and 18, giving 16.5, which cannot be an INTEGER.
On the board or with the pen
- Write Quantity 4, Total 340, Pounds 3, Pence 40 as a quick list; write the average program as pupils dictate it.
Checking understanding: The till question has four options built from slips in the DIV and MOD of 340; the written program shows whether declarations, input and brackets are secure.
Depending on the answers
- If pupils choose 3 pounds and 4 pence: ask them to work out MOD(340, 100) and compare with 4.
- If pupils write the average without brackets: trace marks 15 and 18 and ask what the output is.
Stretch
- Change the till so that the price is 90 pence. Which line changes, and why?
In the lesson window
- Apply it: A pupil buys 4 snacks. What does the program output?
- Think it through: Write a program in Cambridge pseudocode that declares what it needs, inputs two test marks (whole numbers out of 20) and outputs their average. Mention which data type the average needs, and why.
9. Show what you know Consolidate 5 min
On the lesson window now
Purpose: Pupils explain variable against constant, and apply BOOLEAN to a new situation, before the summary.
Ask
- What is the difference between a variable and a constant, with one example of each from a canteen till?
- Which type records whether homework is in?
Responses to expect
- Running total as a variable and snack price as a constant
- BOOLEAN, because there are two possible values
Misconceptions to challenge
- A learner may believe: “A STRING is best because the words Done and Missing are text.” Respond: A STRING would allow any text, including mistakes like Dne. The words are chosen from the BOOLEAN when displayed.
- A learner may believe: “INTEGER with 1 and 0 is equally good.” Respond: An INTEGER allows any whole number, not just 1 and 0.
Checking understanding: Collect the explanations: a good one says what changes and what does not.
Depending on the answers
- If pupils choose STRING: ask what a program would do with the value Dne, and which type can only hold two answers.
- If several are unsure of DIV and MOD: start the next lesson with a two-minute quiz: DIV(20, 6) and MOD(20, 6).
In the lesson window
- Think it through: Explain to a friend the difference between a variable and a constant, with one example of each from a school canteen till.
- Apply it: A school’s fictional app stores whether each pupil has handed in their homework, and shows ‘Done’ or ‘Missing’. Which data type is best for the variable that records whether the homework is in?
Lesson recap Closing
On the lesson window now
On screen: the lesson’s objectives again; Next adds the closing question, which asks the class to explain each one in their own words without looking back. It says nothing about what anyone has learnt: use the answers to decide what to revisit.
Points to listen for
- A variable holds a value that can change; assignment works out the right side first and stores the result on the left.
- A constant is set once; DECLARE names a variable and its type; names start with a capital.
- The five data types are INTEGER, REAL, CHAR, STRING and BOOLEAN; choose by how the value is used.
- INPUT stores what the user types; OUTPUT shows values; the order of lines matters.
- DIV counts whole times, MOD gives the remainder; each side of AND and OR must be a complete test.
Consolidation
- A variable holds a value that can change; assignment works out the right side first and stores the result on the left.
- A constant is set once; DECLARE names a variable and its type; names start with a capital.
- The five data types are INTEGER, REAL, CHAR, STRING and BOOLEAN; choose by how the value is used.
- INPUT stores what the user types; OUTPUT shows values; the order of lines matters.
- DIV counts whole times, MOD gives the remainder; each side of AND and OR must be a complete test.