C17 · Topic 3.1 · 40 minutes · AAP-1.A, AAP-1.B
Variables and state
By the end you can:
- Choose a meaningful representation for a value.
- Distinguish a value from its variable name.
- Explain how assignment changes current state.
Before this lesson: topics 1.2.
- Variable
- A named reference used to represent a value that can change during a computation.
- Assignment
- Storing the value of an evaluated expression in the named variable.
Understand
A variable lets a programme refer to a value by a name. Choose a representation that fits its use: a count is numerical, a yes/no property is Boolean, and a label such as a room code is text even when it contains digits. A meaningful name helps explain intent but does not guarantee the stored value is correct.
Assignment evaluates the right side using current values and stores that result on the left. It is not a mathematical claim that both sides remain equal forever. When one number is assigned to another variable, a later assignment to the original does not automatically change the copied value.
Worked example
A room model starts seats←12, then backup←seats, then seats←seats−3.
seats ← 12 backup ← seats seats ← seats - 3
- After the first line,seats is 12.
- backup receives the current value 12.
- The final line stores 9 in seats; backup remains 12.
Explore each concept
Choose a concept, change its inputs and follow the explanation. Each example models the stated rule or scenario; completing it is practice rather than evidence of mastery.
- Names versus values
- Number, string, Boolean and list
- Copy then update
Change it · step through · explain
Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.
Ready · Make a prediction
- Value typenumberWaiting
- Original number (0–99)7Waiting
Ready to explore: Value types and independent copies
Why: Change an input, predict the first effect, then advance one step.
Try this: Change one input or choose another listed case. Predict the effect, reset and compare the states and governing rule.
Step through and experiment
Change it · step through · explain
Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.
Ready · Make a prediction
- Input 14Waiting
- Input 29Waiting
- Input 35Waiting
Ready to experiment
Why: Predict the first change, then advance one step.
Try this: Change one input, predict the difference, then reset and compare.
Check a misconception
Claim: Assigning backup←seats creates a permanent link between them.
For these numerical values it copies the current value; later assignments change only their target.
Guided practice
Give the final values of seats and backup and explain their difference.
Work with a partner. Make a prediction, compare your reasoning, then identify the rule that supports your answer.
Independent transfer
Choose representations for a room code “007”, available places 7 and whether a booking is confirmed.
Exit check
Why does a variable name not determine a value by itself?
Write your reasoning before comparing with a classmate. If your teacher assigned this task, submit it through My classes to save your work and receive feedback.
Check yourself
Your practice so far
Check an answer to see its rationale.