GCSE · Computer Science · OCR · Spec J277
Sub programs: procedures
Typing the same menu out ten times, then fixing every copy when one option changes? No thanks. Write it once, name it, and call it whenever you need it.
Programming · Define, then call
One menu, two calls
Step through this Python program. Watch which line is running, what the parameter player holds, and what appears in the output.
Predict before you step: on which step will Welcome, Asha first appear, and how many times will the menu be shown?
1 def show_menu(player):2 print("Welcome, " + player)3 print("1. Play")4 print("2. Quit")5 # main program6 show_menu("Asha")7 show_menu("Ben")
Variables
Output
Step 1: Python reads the def line and the indented lines under it. That defines a procedure called show_menu with one parameter, player. player has no value yet, and the output box is empty: defining the procedure hasn't run it.
Use Next and Back. Keep an eye on the line marker: it jumps from the call into the procedure.
Programming · Which kind of subprogram?
Procedure or function?
Does this subprogram return a value to the program, or not?
Still to sort
Procedure (0)
Runs its commands when called. Returns no value.
Where the line is: Doing something useful, like displaying text, doesn't make it a function. If nothing is returned, it's a procedure.
Function (0)
A subprogram that also returns a value.
Where the line is: Doing a calculation isn't the test. Returning a value to the calling program is.
Each of these is a subprogram. Decide which kind it is, then read why.
Why bother with procedures?
Reason it through
Why put a game's menu code in a procedure instead of typing it out every time it's needed?
First link · your turn
The menu code goes into a procedure called show_menu. What can the main program now do whenever it needs the menu?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
A named block of code that sits quietly until the main program calls it, then does its job as often as you ask.
What you need to know
- A subprogram is a section of code that does one specific job, and the main program can call it whenever it's needed.
- A procedure runs its commands when it's called but returns no value; a function is a subprogram that also returns a value.
- print() is a procedure you already know, and you can write your own, like one that displays a menu.
Have a goYour mate is certain print() is a function, "because it actually does something". Using the rule you've just read, set them straight.
It's a procedure: it carries out its job but returns no value.
Doing something isn't the test, because procedures and functions both do things. Only a function also hands a value back to the program.
- Repeated code like a menu belongs in a procedure: call it as many times as you like, and change it just once.
- In Python, a procedure starts with def, then its identifier (a meaningful name you choose), then any parameters in brackets.
- Defining a procedure doesn't run it. Nothing happens until the main program calls it.
Have a goJas writes a perfect def block for a procedure called cheer, presses Run and gets... nothing. "Python's broken!" What's really missing?
A line in the main program that calls cheer.
Python's fine. The def block only set the procedure up; without a call, its commands never run.
- Parameters define the data a procedure needs when it's called, and inside the procedure they're treated as local variables.
- A call is the procedure's name followed by the arguments; each argument's value is passed into a parameter.
- Argument and parameter names don't have to match, but there must be the same number of arguments as parameters.
Have a goA procedure is defined as def party(host, guest, food):. How many arguments must every call to it give?
Three.
Three parameters need three arguments. What the arguments are called doesn't matter; how many there are does.
The big picture
A subprogram is a section of code that does one specific job and can be called whenever the main program needs it. Procedures run their commands but return no value; functions also return a value. In Python you define a procedure with def, its identifier and any parameters in brackets, but defining it doesn't run it: the main program has to call it, giving one argument for each parameter.
Key points
Worked example
Problem
A Python program defines greet_both(first, second), which prints "Hi " + first and then "Hi " + second. The main program sets a = "Kai" and b = "Zoe", then calls greet_both(b, a). What does the program print?
⚠ Watch out
Thinking that writing a def block runs the procedure. It doesn't: the procedure only runs when the main program calls it, so a program with a definition and no call prints nothing from it.
Memory hook
A def block is a recipe card filed in a drawer: nothing gets cooked until someone calls for it by name and hands over the ingredients. One card, one ingredient for each blank, as many meals as you like.
Check yourself
Cover the page. Using def show_menu(player): and the call show_menu("Asha") as your example, explain the difference between a parameter and an argument, and say what happens to "Asha" when the call runs.
Flashcards
(11)What is a subprogram?
What are the two kinds of subprogram?
Procedure vs function: what's the difference?
Name a procedure you've already used.
Why put a menu in a procedure?
Which keyword starts a procedure definition in Python?
In a def line, what is the identifier?
When does the code inside a procedure run?
What do parameters do?
What does a procedure call consist of?
Must an argument have the same name as its parameter?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore OCR GCSE Computer Science topics
How this lesson was checked. This OCR GCSE Computer Science (specification J277)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 3 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.