GCSE · Computer Science · Edexcel · Spec 1CP2
Built-in and user-devised subprograms
You have used subprograms since your first line of Python. print() is one, input() is another, and one of them has quietly been handing you something all along.
Computer Science · Subprograms
Follow the call: what runs, what travels in, what comes back
This program defines a menu procedure and a function called add. Step through it and keep asking: has anything actually run yet?
Press Next one step at a time. Before each press, predict: has the screen output changed?
1 def show_menu():2 print("1. Play")3 print("2. Quit")4 def add(x, y):5 total = x + y6 return total7 print("Done")8 show_menu()9 answer = add(10, 15)10 print(answer)
| x | y | total | answer |
|---|---|---|---|
Output
Step 1: Python reads the first def line and remembers the name show_menu. It does NOT run the two print lines inside. Look at the output: still empty.
Step through the trace — every value is the lesson’s, not run by the page.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Procedures, functions, and how a call sends values in and gets one back
What you need to know
- A subprogram is a section of code designed to do one specific task, called by the main program whenever it is needed.
- A procedure runs its code but returns no value. A function returns a value to the calling program.
- print() and input() are subprograms you have already used. User-devised subprograms are the ones you create yourself.
- Defining a subprogram does not run it. The code only runs when the main program calls it.
Have a goJo writes def party(): with print("Cake!") inside it, runs the program, and the screen stays empty. Jo says Python is broken. What really happened?
Jo defined party but never called it.
Defining a subprogram does not run it. Nothing runs until the main program calls it, for example with party().
- A call passes control, and any arguments, into the subprogram, where the parameters receive the values.
Have a goThe def line is def cheer(team): and the call is cheer("Reds"). Which value ends up inside team, and what is "Reds" called in the call?
"Reds" ends up in team, and in the call it is an argument.
Arguments are the values in the call's brackets, and they travel into the subprogram through the parameters. team is the parameter that receives it.
- Parameters are treated as local variables inside the subprogram. A subprogram can have no, one or more parameters.
- Arguments and parameters can have different names, but a call needs the same number of arguments as parameters.
- When return runs, the function ends, so any line after it in the function does not execute.
Have a goA function has return 5 on one line and print("hi") on the very next line. You call it once. How many times does hi appear?
None. The print line is never reached.
When the return line runs, the function ends at once, so a statement after it in the function does not execute.
- A returned value must be stored in a variable if the calling program wants to use it later.
- A variable made inside a subprogram can only be seen inside that subprogram, so the main program cannot see it.
The big picture
A subprogram is a named section of code that does one job and only runs when it is called. A procedure just does the job. A function also hands a value back, and that value is lost unless the calling program stores it. Arguments go in through parameters, return sends a value out, and variables made inside a subprogram stay inside it.
Key points
Worked example
Problem
Write a procedure called greet that takes one value, name, and displays Hello followed by the name. Then call it twice, once for Sam and once for Priya.
⚠ Watch out
Mixing up parameters and arguments. Parameters are the names in the def line; arguments are the actual values in the call's brackets. The names do not have to match, but the number of arguments must match the number of parameters.
Memory hook
Think of a subprogram as a recipe card. Writing the card cooks nothing; the call does the cooking. A function also hands back the dish, and you need a plate (a variable) to keep it.
Check yourself
Pick any subprogram from this lesson without looking back. Say out loud whether it is built-in or user-devised, whether it is a procedure or a function, and what, if anything, comes back from it.
Flashcards
(14)What is a subprogram?
What is a procedure?
What is a function?
Does a def line run the subprogram?
What is a call?
What is a parameter?
What is an argument?
How many parameters can a subprogram have?
What does return do in a Python function?
How do you keep the value a function returns?
Can the main program see a variable made inside a subprogram?
Which Python keyword defines a subprogram?
What are built-in and user-devised subprograms?
Why is print() a procedure but input() a function?
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 Edexcel GCSE Computer Science topics
- Code readability techniques
- Converting algorithms to programs
- CSV file I/O
- Decomposition and abstraction in programming
- Evaluating program fitness and efficiency
- Functions vs procedures
- Global vs local variables
- Identifying and correcting program errors
- Primitive data types
- Programming – condition-controlled repetition
- Programming – count-controlled repetition
- Programming – iteration over data structures
How this lesson was checked. This Edexcel GCSE Computer Science (specification 1CP2)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 14 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.