Back to Subprograms
N
Oak National Academy
Lessons written by expert teachers in England, each with slides, a video and quizzes.
Their topic:
Programming: subprograms
For your topic:
Subprograms · Computer Science - 4CP0
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
1
Functions in programs
2
Procedures in programs
3
Structured programs
Lesson 1 of 3 · GCSE level, ages 14 to 16
Functions in programs
By the end:
I can create a program that uses a function to return values.
Key learning points
A function is a named block of code that is called to perform a task and will return a value.
A return value is a value that is returned to the calling program.
Arguments are values provided to a subprogram at the time it is called.
Subprogram parameters are values used by the subprogram that are passed from the arguments when it is called.
Keywords
function
a subprogram that returns a value
return value
a value that is returned by a function
parameter
used in a subprogram to allow values to be passed into them
argument
values held in the brackets of a subprogram call, which are passed into a subprogram 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.
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?
to repeat a block of code multiple times
to store and retrieve data
to organise code
to perform a specific task and return a value
Which keyword is used to define a function in Python?
func
function
def
define
What are the values passed to a function called?
parameters
variables
arguments
constants
A function can have __________ parameters.
only one
zero, one or more
no
Check answers
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 in programs
By the end:
I can create and call a procedure in a program.
Key learning points
A procedure is a named block of code that performs a specific task.
Procedures are designed to run a sequence of code that does not return any value to the calling program.
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 subprogram
procedure
a subprogram that executes a block of code when called but does not return a value
function
a subprogram 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 subprogram that returns a value whereas a procedure is a type of subprogram 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)```
a procedure
a function
iteration
selection
What keyword is used to define a subprogram in Python?
def
sub
input
print
Check answers
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 programs
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
As programs grow in complexity it becomes useful to structure them in a way that is more manageable for the programmer.
A structured approach to programming uses a module approach where a program is seperated into subprograms.
A program can be decomposed into smaller subprograms that are easier to solve indepedently.
The interface determines how data will be passed in and out of the subprogram.
Keywords
subprogram
a sequence of instructions to perform a specific task with an identifiable name
interface
describes how a subprogram will interact with the main program
indentifer
a name for a variable or subprogram
parameters
used in a subprogram 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 subprogram 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.
Subprograms make use of return values so the use of global variables is reduced.
A structured program will execute more quickly.
Subprograms are easier to test because they perform a single task.
Meaningful identifiers for subprograms help to make the program code readable.
It is quicker because many subprograms can be worked on at the same time.
Select the statement that is true.
A subprogram must be defined and executed at some point in the program.
Subprograms make programs easier to read and understand.
Procedures allow values to be returned to the procedure call.
What is num1 in this line of code? ```def display_sum (num1, num2):```
identifier
return value
parameter
variable
Check answers
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.