OCR J277 | Component 02 | 2.2 Programming fundamentals | 2.2.1
Variables, Constants and Assignment
Quest Briefing
OCR J277 2.2.1 expects you to understand how programs store and update values. In this quest, memory is your inventory: variables hold values that can change, constants mark values that should stay fixed, and assignment puts data into a named place.
By the end of this quest, you can...
Stage 2
Learn
Open each concept below to revise the key ideas.
What You Need To Know
A variable is a named storage location used by a program. The value inside it can change while the program runs. Assignment means giving a variable a value, such as score = 10.
A constant is a value that should not change during the program. Python does not force constants, but programmers often write them in capitals, such as MAX_LIVES = 3, to show the value should be treated as fixed.
When tracing code, work from top to bottom. The right-hand side is calculated first, then the result is stored in the variable on the left.
Concept Visual
Program Control Flow
Sequence, selection and iteration control how instructions run.
Stage 3
Apply
Interactive Apply
Labelled memory boxes
Variables, constants and assignment ยท Inspect changing state
- 01Guided
- 02Independent
- 03Diagnose
- 04Mastery
Topic-native Apply mission
Labelled memory boxes
Your role: Systems technician. Manipulate the Computer Science model, justify the outcome and complete mastery.
- 01Guidedscore stores 25.
- 02IndependentCommit to the outcome before it is revealed.
- 03DiagnoseCompare the result with the likely misconception.
- 04MasteryJustify why the system behaved that way.
Labelled memory boxes
Variables, constants and assignment
Assignment replaces a variable's stored value while a constant remains fixed.
Activate the relevant system controls, then predict the resulting behaviour.
- Createscore stores 25.
- AssignThe new value 30 replaces 25.
- Protect constantMAX_LIVES remains unchanged.
Worked Example
score = 0
score = score + 10
print(score)
The program starts with score as 0. It calculates score + 10, giving 10, then stores 10 back in score. The output is 10.
Common Mistakes Tips
Confusing assignment with comparison
A single = stores a value; comparisons use operators such as == or >=.
Changing constant-style values
Leave MAX_LIVES unchanged unless the task tells you to change it.
Ignoring sequence
Trace the code from top to bottom because later assignments can replace earlier values.
Using unclear names
Choose names such as score or level so the purpose is obvious.
Stage 4
Mission
Coding Mission
Try the coding task
Run the same local check a student receives. Nothing is saved.
Use
Task
- 1 Change the score increase from 10 to 25.
- 2 Create a new variable called level.
- 3 Set level to 1.
- 4 Print player_name, score, MAX_LIVES, and level.
Expected
- Ada
- 25
- 3
- 1
Checked automatically
- score is 25
- player_name is still "Ada"
- MAX_LIVES is still 3
- level is 1
Mission Workspace
Write and test your code
Edit, run and check the code locally. Nothing is saved.
Output
Python is loading...
Stage 5
Complete
Quick Check
Trace this code:
score = 5
score = score + 2
score = score * 3
What is the final value of score?
Expected answer: 21