Skip to content
Menu

Year 10 (ages 14–15, Grade 9 in the US) · Computing · GCSE programming · Lesson 9

Subroutines: functions and procedures

Writing subroutines in Python with def: procedures that carry out a task, functions that return a value, parameters and arguments, and why subroutines make programs easier to write, test and maintain.

Exam boards: this lesson matches the AQA and Pearson Edexcel GCSE computing courses. Check which course your school follows.

Whiteboard video lesson: Subroutines: functions and procedures

8-minute video lesson

Teaching, worked examples and 20 practice questions solved step by step.

Watch free for a month

What your child will learn

  • Define and call a subroutine
  • Use parameters and arguments
  • Distinguish functions and procedures
  • Explain the benefits of subroutines

The method

  1. def name(parameters): defines a subroutine.
  2. Call it by name with arguments.
  3. A function returns a value; a procedure does not.
  4. Benefits: reuse, testing, readability, teamwork.

Key words: subroutine, function, procedure, parameter, return.

Worked examples

Worked examples from the lesson, with every step.

Question 1

What does this output? c:def double(n): c: return n * 2 c:print(double(7) + 1)

  1. Step 1: double(7) returns 14
  2. Step 2: 14 + 1 = 15

Answer: 15

Question 2

Identify the parameters and arguments: c:def add(a, b): c: return a + b c:total = add(5, 9)

  1. Step 1: a, b
  2. Step 2: 5, 9

Answer: parameters a, b; arguments 5, 9

Question 3

Function or procedure? A subroutine that prints a menu.

  1. Step 1: Does it return a value?
  2. Step 2: No — it only prints.

Answer: procedure