Subprograms: functions and procedures
Subprograms are named blocks of code you can call whenever you need them. They are how big programs stay organised.
Functions and procedures
def area(width, height):
return width * height
print(area(4, 5))
A procedure carries out a task but does not return a value.
def greet(name):
print("Hello", name)
greet("Kai")
Parameters are the names in the brackets (width, height). The values passed in when it is called (4, 5) are the arguments.
Built-in and library subprograms
Library subprograms are imported, for example:
import random
dice = random.randint(1, 6) gives a whole number from 1 to 6 inclusive.
Local and global variables
A global variable is created in the main program and can be read anywhere.
Using local variables avoids one part of a program accidentally changing another.
Benefits of subprograms: code is reused instead of repeated, each part can be tested on its own, programs are easier to read, and work can be shared in a team.
What does this print?
x = 10
def change():
x = 5
return x
y = change()
print(x + y)
- x = 5 inside change() is a new local variable.
- The global x is still 10, and y = 5.
- 10 + 5
Answer: 15
Functions return values; procedures do not. Parameters receive values passed in. Local variables exist only inside the subprogram. Subprograms make code reusable, testable and readable.
- Subprogram
- A named block of code that can be called: a function or a procedure.
- Function
- A subprogram that returns a value.
- Procedure
- A subprogram that carries out a task but does not return a value.
- Local variable
- A variable declared inside a subprogram that can only be used there.
- Variable
- A named store whose value can change while the program runs.
- Global variable
- A variable declared in the main program that can be used anywhere in it.
All GCSE and International GCSE Computer Science key terms and definitions →
Try two quick questions
See if it has sunk in. Answers are marked straight away.
2 more questions
Try each one, then tap to check.
What does this print?
def area(width, height):
return width * height
print(area(9, 4))Show the answer
Answer: 36
width = 9 and height = 4, so it returns 9 × 4 = 36.
What does this print?
def triple(n):
return n * 3
print(triple(triple(2)))Show the answer
Answer: 18
The inner call gives triple(2) = 6, then triple(6) = 18.
Check you have got it
Answer 7 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.
- Pearson Edexcel GCSE Computer Science (1CP2) specification, topic 1.1.2, 6.6
- Pearson Edexcel International GCSE Computer Science (4CP0) specification, topic 2.3.5, 2.6
- Pearson Edexcel GCSE Computer Science (1CP2) sample assessment materials and Programming Language Subset
Facts checked against the sources below, 16 October 2026. Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.
What do exam command words like explain and evaluate mean? →