Parameters, return values and local variables – AQA GCSE Computer Science lesson (8525)
Pupils learn to pass data into subroutines with parameters, return values, and explain why local variables are good practice, in the class's language and AQA pseudo-code.
Lesson 4 of 14 in unit 11.1 Cyber Security and Robust Programs, taught in Year 11, Autumn 1. It answers one big question: How does data get in and out of a subroutine safely?
By the end, pupils can pass data into subroutines with parameters, return values, and explain why local variables are good practice, in the class's language and AQA pseudo-code.
- The Build (the main task)
- Write a program that: has a function basketTotal that takes the price and the quantity as parameters; works out the total in a local variable and returns it; inputs a price and a quantity from the user; calls basketTotal with those values and outputs the value it returns. You should use indentation and meaningful identifiers. (6 marks) Explain what is meant by a local variable. (2 marks)
- Support version
- Part-filled code with the function header written and the call to complete.
- Challenge
- Explain why using local variables makes subroutines easier to reuse and to test. (4 marks) Write a program with a function pairsLeft that takes the pairs in stock and the pairs sold as parameters and returns how many are left, using a local variable. Input both values, call the function, output the result and output Reorder if fewer than 5 pairs are left. (6 marks)
- Real-world link
- Kickstand's basket total for each order.
- Key words
- Parameter, Return value and Local variable, each with a definition, an icon and a common mix-up on the key vocabulary slide.
- Misconceptions it tackles
- “A local variable keeps its value after the subroutine ends”; “The parameter name must match the variable name used in the call”.
- AQA 8525 specification
- 3.2.10 (structured programming and subroutines).
Every lesson follows the same Code & Commerce structure: a Bell Task recall starter, key vocabulary with definitions and icons, short teaching chunks with a check before pupils move on, The Build (one main task), challenge questions that get harder, and an exit question. Answers reveal one at a time on the slides, and everything is editable PowerPoint and Word.
Pupils need computers for the main task.
Also sold in the Cyber Security and Robust Programs unit bundle, which includes the medium term plan, and in the full-year and complete-course bundles.
Choose your school's Paper 1 language when you buy: C#, Python or VB.NET. You get that language's files: every program, code example, worked answer and programming task is written in it, and lessons with no code are the same in all three. Algorithms are also shown in AQA pseudo-code, as in the exam.
An independent resource written for AQA GCSE Computer Science (8525). It is not endorsed by AQA.
What's included
- Slide deck (PowerPoint)
- Lesson plan (Word)
- Worksheet (Word)
- Support worksheet with scaffolds (Word)
- Single-teacher licence: use and adapt it with your own classes
- Your choice of Paper 1 language: C#, Python or VB.NET
More for GCSE Computer Science (AQA)
See allPupils learn to define cyber security, describe its purposes, and describe viruses, trojans and spyware and how to protect against them.
Pupils learn to explain what a subroutine is, tell procedures from functions, and write and call both in the class's language and AQA pseudo-code.
Pupils learn to describe blagging, phishing and shouldering and how to protect against social engineering.
Written for the specifications named. Not endorsed by or affiliated with any exam board.