Community resourceWorksheet

J277 2.2.3 Procedures, scope and passing arrays

Part 5 of 5 · J277 2.2.3 · Strings, arrays and functions

Procedures, local and global scope, and passing arrays into and out of subprograms.

Students will:

  • distinguish a procedure from a function
  • explain local and global scope
  • pass a list into a subprogram
  • return an updated array from a subprogram
  • choose between a procedure and a function for a task

Inside: 5 explanation cells, 3 runnable Python tasks, 2 multiple-choice questions, 1 fill-in-the-blanks cell and 3 written answers. 21 marks, about 60 minutes.

Series: J277 2.2.3 · Strings, arrays and functions, part 5 of 5.

Shared by Coding PathwayVerified teacher

  • 14 cells
  • About 60 minutes
  • CC BY-SA 4.0
  • Shared 17 Aug 2026
  • Updated 9 Sept 2026

Preview

The whole resource, exactly as a class sees it. Answers and marking are held back.

Procedures, scope and passing arrays

A procedure is a named subprogram that performs a task without returning a value for use by the caller. In Python, procedures are written with def, just like functions, but do not use return to send back a result. OCR also expects local and global scope and arrays passed to or returned from subprograms.

A local variable is created inside a subprogram and is normally accessible only there. A global variable is created outside subprograms and is accessible more widely. Passing data as a parameter usually makes a subprogram's required input clearer than silently depending on global data.

Multiple choice1 mark

Where is a local variable normally accessible?

  • AIn every program on the computer
  • BOnly inside print()
  • CBefore it is assigned
  • DInside the subprogram in which it is created

Scope and data flow

  • A local variable is created inside a subprogram and is normally accessible only there.
  • A global variable is created outside subprograms and can be accessed more widely. Excessive global data can make programs harder to understand and test.
  • Constants can also have local or global scope. A fixed rule used only by one subprogram can be a local constant; a fixed rule needed by several subprograms can be a global constant.
  • A list can be passed as an argument. A subprogram can process it, modify it, or return a new list, depending on the design.

OCR Exam Reference Language uses procedure name(parameters) ... endprocedure for a procedure and function name(parameters) ... return value ... endfunction for a function. Python uses def for both, so decide from the purpose: a function returns a value for the caller to use; a procedure performs a task without returning such a result.

Global and local scope around a subprogram TAX_RATE is defined in the wider global scope. A list argument enters the show_total procedure through the prices parameter. The variable total is local to show_total and is not available outside that subprogram. Global scope TAX_RATE = 0.2 global constant Inside show_total(prices) local scope boundary prices parameter total local variable argument [5, 10, 15] not accessible outside

Before running the example below, identify TAX_RATE, prices and total as global constant, parameter and local variable. Predict the displayed total, then check how the procedure uses passed data without returning a result.

Worked example
TAX_RATE = 0.2

def show_total(prices):
    total = 0
    for price in prices:
        total = total + price
    print(total + total * TAX_RATE)

show_total([5, 10, 15])
Fill in the blanks3 marks
A variable created inside a subprogram normally has label 1 scope. A value created outside and accessible more widely has label 2 scope. Data supplied to a subprogram is passed as an label 3.
  • local
  • global
  • argument
  • output
  • index

Supported practice: a procedure receiving a list

Complete show_items(items) so it displays every element in the list supplied by the caller. Replace pass with a loop and print the current item on each repetition.

For the supplied list, the output must contain pen, book and ruler on separate lines. The order matters because it should match the list.

Coding task3 marks
# Complete this procedure so it displays every item in the passed list.
def show_items(items):
    pass

show_items(["pen", "book", "ruler"])
Multiple choice1 mark

Why is passing scores as a parameter usually clearer than making a subprogram depend on a global scores list?

  • AThe required input is explicit and different lists can be supplied
  • BParameters prevent all loops
  • CGlobal variables cannot store lists
  • DParameters automatically sort the list

Independent practice: return an updated array

Complete add_bonus(scores, bonus) so it creates and returns a new list. Loop through every score, add the bonus, append the result to a local list and return that completed list.

Do not print the list or ask for input inside the function. The returned value must be reusable by the calling program, and the checks will call the function with another list and bonus.

Coding task4 marks
# Return a new list containing each score increased by bonus.
def add_bonus(scores, bonus):
    pass

updated = add_bonus([10, 15, 20], 3)
Written answer4 marks

In the worked example, identify one global constant, one parameter and one local variable. Explain why total is local.

Use the exact names from the code and link local scope to where the variable is created and needed.

Students type their answer here.

Written answer3 marks

Compare a function with a procedure in exam-board terms, while recognising how both are written in Python.

State the key difference in the value returned to the caller, then state one similarity.

Students type their answer here.

Written answer2 marks

Explain one risk of using many global variables in a large program.

Link wider access to unintended changes, dependencies, testing or debugging.

Students type their answer here.

Review

Subprograms are easier to reuse and test when their required data is made explicit through parameters. Use local variables for temporary work, return a value or new array when the caller needs it, and avoid unnecessary dependence on global variables.