Procedures and functions – OCR GCSE Computer Science lesson (J277)
Pupils learn to write and call a procedure and a function in Python, and explain the difference between them and why subprograms are reused.
Lesson 2 of 14 in unit 11.1 Cyber Security and Robust Programs, taught in Year 11, Autumn 1. It answers one big question: Why do programmers split code into procedures and functions?
By the end, pupils can write and call a procedure and a function in Python, and explain the difference between them and why subprograms are reused.
- The Build (the main task)
- Write a function discount_price that is given a price and returns the price with Kickstand's 20% sale discount, then call it for three trainers and print each result.
- Support version
- Parsons problem: the function's lines jumbled, with one distractor line that prints instead of returning.
- Challenge
- Write a procedure print_receipt that prints a trainer's name and its sale price, calling discount_price inside it.
- Real-world link
- Kickstand's sale page works out the same 20% discount for every trainer.
- Key words
- Subprogram, Function and Reuse, each with a definition, an icon and a common mix-up on the key vocabulary slide.
- Misconceptions it tackles
- “A function and a procedure are the same thing”; “Defining a subprogram runs it”.
- OCR J277 specification
- 2.2.3 (additional programming techniques: subprograms (procedures and functions), parameters and return values, local and global variables, and random number generation); 2.3.1 (defensive design: anticipating misuse, authentication, input validation, and maintainability (subprograms, naming conventions, indentation and comments)).
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.
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
More for GCSE Computer Science (OCR)
See allPupils learn to describe how viruses, worms, trojans, spyware and ransomware work and the harm each can do to a business like Kickstand.
Free sample lessonPupils learn to describe phishing and other social engineering, spot the signs in a fake message, and explain how staff training reduces the risk.
Pupils learn to pass arguments into parameters, return values from functions, and explain the difference between local and global variables.
Written for the specifications named. Not endorsed by or affiliated with any exam board.