Sequence
Follow instructions in the order they are written.
Sequence means carrying out instructions one after another in order. The result of an earlier statement can affect every statement that follows it.
Predict
Read the code first. Do not run it yet.
x = 4
y = x + 3
x = y * 2
print(x, y)- Trace the values after each line.
- What are the final values of
xandy? - Why does changing the order of the assignments change the result?
Investigate
Use this code to explain exactly how the program works.
length = 8
width = 5
area = length * width
print("Area:", area)- Identify the input values already stored in variables.
- Identify the processing statement.
- Identify the output statement.
Input, process, output in sequence
A simple program often follows an input → process → output sequence.
length = 8
width = 5
area = length * width
print("Area:", area)Area: 40
- The first two statements establish the values to use.
- The third statement processes those values.
- The final statement outputs the result.
Tracing a program
A trace table records how variable values change as an algorithm runs. Work through the statements in order and update the table whenever a tracked value changes.
total = 0
for number in range(1, 4):
total = total + number
print(total)| number | total after the assignment |
|---|---|
| 1 | 1 |
| 2 | 3 |
| 3 | 6 |
Self-study guide
Sequence means instructions are carried out in order, one after another. This sounds simple, but many programming errors come from using a value before it has been created or calculating things in the wrong order.
A useful way to think about sequence is data flow: input values are obtained first, calculations produce intermediate values next, and results are output only after the required values exist.
OCR Exam Reference Language ↔ Python
| OCR Exam Reference Language / term | Python | What to remember |
|---|---|---|
Sequence | top-to-bottom statements | There is no special OCR or Python keyword for sequence. |
x = 4
y = x + 3 | x = 4
y = x + 3 | The assignment form is the same. |
Input → Process → Output | input() → calculations → print() | A common sequence structure. |
Worked example
Every statement here depends on values created earlier.
price = 12.50
quantity = 3
subtotal = price * quantity
delivery = 2.00
total = subtotal + delivery
print(subtotal)
print(total)37.5 39.5
priceandquantitymust exist beforesubtotalcan be calculated.subtotalmust exist before it is used in the final total.- The outputs are last because they depend on the completed calculations.
- Moving
total = subtotal + deliveryabove the creation ofsubtotalwould make the program invalid.
Another example
Tracing sequence means recording changes at exactly the line where they happen.
x = 4
y = x + 3
x = y * 2
print(x, y)14 7
- After line 1: x = 4.
- After line 2: y = 7 while x is still 4.
- After line 3: x changes to 14; y stays 7.
Common mistakes
- Using a variable before it has been assigned.
- Mentally applying all assignments at once instead of one line at a time.
- Assuming a later change to
xautomatically changes a value already stored iny.
Exam-ready checklist
- Identify sequence in an algorithm.
- Trace assignments in order.
- Rearrange statements into a valid sequence.
- Explain why one calculation must happen before another.
What you have learned
- Sequence runs instructions in order.
- Earlier assignments can affect later calculations.
- Simple programs often follow input, process, output.