SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
Edexcel 1CP2 · Topic 2 · 2.5

Subroutines:
Functions & Procedures

Parameters · Return Values · Local/Global Scope · Benefits of Subroutines

CSZoneEdexcel GCSE Computer Science 1CP2
Functions vs Procedures

Two Types of Subroutine

Function: a named block of code that performs a task and returns a value. e.g. calculate area and return the result.
Procedure: a named block of code that performs a task but does not return a value. e.g. print a welcome message.
def calculate_area(length, width): # function
    return length * width

def print_greeting(name): # procedure
    print("Hello,", name)
Parameters & Arguments

Passing Data into Subroutines

def add(a, b): # a, b are PARAMETERS
    return a + b

result = add(3, 5) # 3, 5 are ARGUMENTS
print(result) # 8
Parameter: variable in the function definition (placeholder)
Argument: actual value passed when calling the function
Functions can take multiple parameters, separated by commas
Local & Global Variables

Scope in Subroutines

Local variable: declared inside a subroutine — only accessible within that subroutine. Created when called, destroyed when it returns.
Global variable: declared outside subroutines — accessible from anywhere. Use sparingly; makes debugging harder.
Edexcel favours using parameters rather than global variables — better practice, more modular code
Exam Practice

Have a go at this question

Edexcel-style question
State two benefits of using subroutines in a program.
2 marks
Any two from: Avoids code repetition — write once, call many times [1]. Makes programs easier to read, understand, and maintain [1]. Allows different programmers to work on different subroutines simultaneously [1]. Easier to test individual sections [1].
Key Takeaways

What to Remember

Function: returns a value; Procedure: no return value
Parameters = placeholders in definition; Arguments = values passed when calling
Local scope: inside only; Global scope: accessible everywhere
Benefits: reduces repetition, improves readability, easier testing