Back to Subroutines (procedures And Functions)

Oak National Academy

Lessons written by expert teachers in England, each with slides, a video and quizzes.

Their topic:
Programming: subroutines
For your topic:
Subroutines (procedures And Functions) · Computer Science - 9210

Use these lessons alongside our lesson note, which covers your syllabus in full.

What this covers in your syllabus

3 lessons from Oak National Academy

Lesson 1 of 3 · GCSE level, ages 14 to 16

Functions

By the end: I can create a program that uses a function to return values.

Key learning points

  1. A function is a named block of code that is called to perform a task and will return a value.
  2. A return value is a value that is returned to the calling program.
  3. Arguments are values provided to a subroutine at the time it is called.
  4. Subroutine parameters are values used by the subroutine that are passed from the arguments when it is called.

Keywords

function
a subroutine that returns a value
return value
a value that is returned by a function
parameter
used in a subroutine to allow values to be passed into them
argument
values held in the brackets of a subroutine call, which are passed into a subroutine via the parameters

A common mistake

Mistake: When a function returns a value it can be used throughout the program that called it.

In fact: The return value needs to be stored if it is to be used later in the program that calls it. If it isn't stored, the value cannot be used again.

Check what you learned

From Oak National Academy's exit quiz. Choose every answer that is right.

What is the primary purpose of a function in programming?
Which keyword is used to define a function in Python?
What are the values passed to a function called?
A function can have __________ parameters.

A computing lesson by Oak National Academy licensed under the Open Government Licence (OGL) v3.0. Read the licence

Lesson 2 of 3 · GCSE level, ages 14 to 16

Procedures

By the end: I can create and call a procedure in a program.

Key learning points

  1. A procedure is a named block of code that performs a specific task.
  2. Procedures are designed to run a sequence of code that does not return any value to the calling program.
  3. In order to run a procedure, it must be called by the main program.

Keywords

call
an expression that passes control and arguments (if any) to a subroutine
procedure
a subroutine that executes a block of code when called but does not return a value
function
a subroutine that returns a value
return value
a value that is returned by a function

A common mistake

Mistake: Functions and procedures are just different names for the same thing.

In fact: A function is a type of subroutine that returns a value whereas a procedure is a type of subroutine that does not return a value.

Check what you learned

From Oak National Academy's exit quiz. Choose every answer that is right.

This code is an example of: ```def calculate(a, b): answer = a + b return answer answer = calculate(5, 10)```
What keyword is used to define a subroutine in Python?

A computing lesson by Oak National Academy licensed under the Open Government Licence (OGL) v3.0. Read the licence

Lesson 3 of 3 · GCSE level, ages 14 to 16

Structured programming

By the end: I can describe what is meant by a structural approach to programming and explain the benefit of this approach.

Key learning points

  1. As programs grow in complexity it becomes useful to structure them in a way that is more manageable for the programmer.
  2. A structured approach to programming uses a module approach where a program is seperated into subroutines.
  3. A program can be decomposed into smaller subroutines that are easier to solve indepedently.
  4. The interface determines how data will be passed in and out of the subroutine.

Keywords

subroutine
a sequence of instructions with an identifiable name that performs a specific task
interface
describes how a subroutine will interact with the main program
identifer
the name that a programmer gives to a variable, constant, or subroutine
parameters
used in a subroutine to allow values to be passed into them

A common mistake

Mistake: A program must run line by line from top to bottom.

In fact: A subrotuine is an 'out of line' block of code, which is typcially written at the top of a program and then called upon within the main program.

Check what you learned

From Oak National Academy's exit quiz. Choose every answer that is right.

The structured approach to programming provides many benefits. From the list below, select the statements that specify a benefit of using the structured approach.
Select the statement that is true.
What is num1 in this line of code? `def display_sum (num1, num2):`

A computing lesson by Oak National Academy licensed under the Open Government Licence (OGL) v3.0. Read the licence

The wording comes from each publisher. The layout and the links to your syllabus are ours.