Community resourceWorksheet
1CP2-CT-1.3 First programs, variables and constants
Part 3 of 7 · 1CP2-CT-1 · Programming foundations
The first Python worksheet of the course, turning an informal algorithm into working code.
Students will:
- predict the exact output order of a short program
- store values in named variables and read them back
- choose between a variable and a constant, and name each conventionally
- follow how a value changes as a program runs
- write a short program of their own and explain an assignment statement
Inside: 9 explanation cells, 2 multiple-choice questions, 3 Python tasks, 2 fill-in-the-blanks cells and 2 written answers. 18 marks, about 45 minutes.
Series: 1CP2-CT-1 · Programming foundations, part 3 of 7.
Shared by Coding PathwayVerified teacher
- 18 cells
- About 45 minutes
- CC BY-SA 4.0
- Shared 17 Aug 2026
Preview
The whole resource, exactly as a class sees it. Answers and marking are held back.
First programs, variables and constants
You already know that an algorithm is an ordered solution method. This worksheet introduces Python as one way to implement a short algorithm.
You will learn how to:
- read and run
print()instructions from top to bottom; - use literals and arithmetic expressions;
- initialise and assign values to variables;
- distinguish variables from constants;
- follow value changes and write a short sequence program.
Every symbol is explained before you use it. User input and conversion belong to the next worksheet.
1. From algorithm to Python
An algorithm describes behaviour. Python expresses that behaviour using exact syntax.
Informal algorithm:
- Output the heading
Plant total. - Multiply 4 by 6 and output the result.
- Output
Complete.
In a Python sequence, execution moves from the first line to the last line. print() displays the value inside its brackets. Text is placed inside quotation marks; numerical expressions are not.
Read this listing without executing it:
print("Plant total")
print(4 * 6)
print("Complete")
Which option gives the exact output order?
- A`Plant total`, then `24`, then `Complete`
- B`Plant total`, then `4 * 6`, then `Complete`
- C`24`, then `Plant total`, then `Complete`
- D`Complete`, then `24`, then `Plant total`
Explain why the second line outputs 24 rather than the characters 4 * 6.
Distinguish an unquoted arithmetic expression from text in quotation marks.
Students type their answer here.
2. Named storage
A variable is a named place used to store a value that may change while a program runs. An identifier is the name used for that storage.
An assignment statement stores the value on the right of = in the name on the left. In Python, = means assign, not compare.
score = 5
score = score + 3
The first line initialises score by giving it its first value. The second assignment reads the current 5, adds 3 and stores the new value 8 back in score.
score = 5
score = score + 3
print(score)score is an label 3.- assignment
- constant
- identifier
- initialisation
- output
3. Variables and constants
A constant is a named value intended not to change while the program runs. Pearson's Python subset uses uppercase names to show that intention:
MAX_PLACES = 30
places_booked = 18
MAX_PLACES is intended to remain 30. places_booked may change. Python does not technically prevent reassignment of an uppercase name, so using it correctly is a programming convention and a design decision.
Meaningful identifiers such as places_booked make code easier to read than vague names such as x. Identifiers cannot contain spaces, so an underscore can separate words.
Which name most clearly follows the convention for a constant storing a fixed ticket price?
- Ap
- Bticket price
- CTICKET_PRICE
- Dticket_price
4. Follow value changes
Work down the program one line at a time and record the new value after each assignment:
items = 4
items = items + 3
items = items * 2
print(items)
| Line completed | Stored value of items |
|---|---|
items = 4 | 4 |
items = items + 3 | 7 |
items = items * 2 | 14 |
The output is therefore 14. The right side is evaluated using the old value before the new value is assigned.
points = 6, points stores 6. After points = points + 4, it stores label 1. After points = points * 3, it stores label 2.- 10
- 18
- 24
- 30
5. Supported programming task
Amend the program below so it:
- initialises
boxesto 5; - initialises
items_per_boxto 6; - assigns
totalthe result of multiplying the two variables; - outputs
total.
The variable names are required because they communicate the algorithm clearly. The expected output is 30.
boxes = 2
items_per_box = 4
total = boxes + items_per_box
print(total)6. Independent programming task
Write a new sequence program for a hall layout. It must:
- create the constant
ROWSwith value 7; - create the variable
seats_per_rowwith value 8; - calculate
total_seatsby multiplying those two named values; - output
total_seats.
Use the stated names. Your program should output 56. No keyboard input is needed.
7. Explain an assignment
For score = score + 2, a precise explanation has two linked parts:
- read the current value of
scoreand add 2; - assign the result back to
score, replacing its previous value.
Saying only “score equals score plus two” does not explain the change and can sound mathematically impossible.
Explain what happens when Python executes stock = stock - 1.
State what is read and calculated, then what value is stored and where.
Students type their answer here.
Route forward
You have implemented sequence using print(), variables, constants, initialisation and assignment. Next you will examine the kinds of values programs store, accept keyboard input, convert that text and repair the first narrow runtime fault.