Revise Computing
Revision notesQuestionsFor schools
Log inStart revising free
Revision notesQuestionsFor schoolsLog in
GCSE Computer Science/Paper 2/Additional Programming Techniques

Sub programs (functions and procedures) to produce structured code

How to use sub programs (functions and procedures) to produce structured code

2.2.3 Additional Programming Techniques

Practise exam questions

Additional Programming Techniques — Note 8 of 12

The difference and use of functions and procedures and where to use them effectively

What you need to know

Sub-programs (also called sub-routines) are reusable blocks of code that perform a specific task. There are two types: functions return a value, while procedures perform a task without returning a value. Using sub-programs makes code modular, reusable, and easier to test and maintain.

What to know

  • A function performs a task and RETURNS a value using the return keyword.
  • A procedure performs a task but does NOT return a value (it may print output instead).
  • Parameters are values passed into a sub-program when it is called. They MUST be used within the function.
  • Sub-programs must be CALLED in the main program to execute. Calling: totalPay = calculatePay(experience, miles).
  • Using sub-programs makes code modular, reusable, and easier to maintain.
  • Code does not need to be repeated; the sub-program can be called multiple times.
  • A procedure is called on its own line: greet("Sarah"). A function call is used inside an assignment or expression, because it gives back a value: total = add(5, 3).

Exam technique

  • Mistake:DO NOT overwrite parameters by asking for input inside the function. If direction and position are given as parameters, USE them — don't do direction = input() inside the function.
  • Tip:A function must RETURN its result — not just print it. Use return total, not print(total), inside the function.
  • Tip:When CALLING a function, string parameters need quotation marks: freeseats("Red"), not freeseats(Red). Store the result: redseats = freeseats("Red").
  • Tip:You can define the function THEN call it separately: result = newPrice(5, "premium") then print(result).
  • Example:Refining to use a function means replacing inline code with a function call: totalPay = calculatePay(experience, miles) then print(totalPay).

Code examples

Function vs Procedure
python
# FUNCTION - returns a value
def newPrice(nights, room):
    if room == "basic":
        price = 60 * nights
    else:
        price = 80 * nights
    return price   # RETURN, not print

# CALLING the function:
result = newPrice(5, "premium")
print(result)  # Output: 400

# PROCEDURE - does not return a value
def greet(name):
    print("Hello, " + name + "!")

greet("Alice")  # Output: Hello, Alice!
Calling a function vs calling a procedure
python
# Function: returns a value
def add(x, y):
    return x + y

total = add(5, 3)    # the returned value is stored
print(total)         # 8

# Procedure: does a job, returns nothing
def greet(name):
    print("Hello", name)

greet("Sarah")       # outputs: Hello Sarah

Ready to test yourself?

Practise 2.2.3 questions
← Previous notetwo-dimensional arrays(2D)2.2.3 Additional Programming TechniquesNext note →local variables2.2.3 Additional Programming Techniques

Back to Additional Programming Techniques

Revise another OCR GCSE topic: Programming Fundamentals

Additional Programming Techniques

Note 8 of 12

  1. 1Concatenation
  2. 2slicing
  3. 3Open, Read, Write, Close
  4. 4Records to store data
  5. 5SQL to search for data
  6. 6one-dimensional (1D)
  7. 7two-dimensional arrays(2D)
  8. 8Sub programs (functions and procedures) to produce structured code
  9. 9local variables
  10. 10global variables
  11. 11arrays
  12. 12Random number generation
Topic overview

© 2026 Revise Computing · revisecomputing.co.uk

Privacy noticeTermsContact

Revise Computing is an independent revision resource. It is not affiliated with, or endorsed by, OCR (Oxford Cambridge and RSA Examinations).