GCSE · Computer Science · Eduqas · Spec C500QS

Subroutines with well-defined interfaces

A subroutine prints 13 on the screen. The caller's variable, which was meant to hold the answer, holds None. Where did the 13 go?

Computer Science · Subroutines

Predict the hand-over

Make each call before the table shows it. Nothing is run: every value is the lesson's, and the only thing being tested is your prediction.

def remaining(total, used):
return total - used
budget = 20
spent = 7
left = remaining(budget, spent)
print(left)
swapped = remaining(spent, budget)
print(swapped)
budgetspenttotal (param)used (param)return valueleftswapped
207

Step 1. Two caller variables so far. The two def lines only describe the subroutine: nothing inside it has run yet. This first row is worked for you.

Step 1 of 9Called right: 0 of 6

Computer Science · Subroutines

Run it and read what Python says

This program should work out 20 - 7 in a subroutine and print 13 once. Press Run, read what Python reports, then choose how to fix the flagged line.

Python 3
  1. def remaining(total, used):
  2. difference = total - used
  3. print(difference)
  4. left = remaining(20, 7)
  5. print(difference)

The messages and outputs are what Python 3.13 gives for this exact code.

Computer Science · Subroutines

Which of these has a well-defined interface?

Tick every property each subroutine has, then check. Think about what each one needs and how its answer leaves.

calculate_area(length, width)
show_total(prices)
add_tax(price)
do_stuff(a, b)
game_turn(score, lives)

Exam line: A well-defined interface: one clear task, a name that describes it, all input through parameters (no globals) and the result passed back through a return value.

Why the inside can change

?

Reason it through

Why can the code inside a subroutine be rewritten without breaking the rest of the program?

Link 1 of 4

First link · your turn

What does a programmer need to know in order to call a subroutine?

2
Locked — reveal the link above first
3
Locked — reveal the link above first
4
Locked — reveal the link above first

Computer Science · Subroutines

Write it, then mark it

A subroutine calculate_area(length, width) returns the area of a rectangle. Describe how it could be tested on its own, and give two benefits of using subroutines with well-defined interfaces. [4 marks]

0 words · your answer stays on this page and is not sent anywhere.

Exam line: Say what you would do (call it with chosen arguments and compare the returned value with the expected result), then name each benefit separately.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

What goes into a subroutine, what comes back, and why nothing else should cross.

What you need to know

  • A subroutine is a named, self-contained block of code that does one specific task. Other parts of the program can call it.
  • A well-designed subroutine has one clear purpose, and its name describes that purpose.
  • Its interface is how it connects to the rest of the program: its name, its parameters and the value it returns.
  • In a call, the arguments are copied into the parameters in order: first to first, second to second.
  • Have a goMaya says arguments find their parameters by matching names. For def join_names(first, last), the call join_names(surname, forename) puts surname into which parameter?

    first. surname is the first argument, so it goes into the first parameter.

    Arguments are copied into parameters in order, so the first argument lands in the first parameter whatever the caller's variable is called.

  • A result comes back to the caller through a return value, which can be stored in a variable or used in an expression.
  • In Python 3, def defines a subroutine, return passes a result back, and a call looks like area = calculate_area(5, 3).
  • In Python 3, a function that ends without a return statement returns None. Printing a result does not pass it back.
  • Have a godef double_show(n): print(n * 2) is called as x = double_show(4). The screen shows 8. What does x hold afterwards?

    None

    double_show has no return statement, so it gives back None. print shows 8 on the screen but does not pass it back to the caller.

  • Variables created inside a subroutine are local: they exist only while it runs and cannot be accessed from outside it.
  • Have a goA subroutine creates a variable called bonus. Straight after the call, code outside it runs print(bonus). What happens?

    It fails: bonus is local, so code outside the subroutine cannot access it.

    A local variable exists only while its subroutine runs, and code outside cannot access it, so the name does not exist out there.

  • A well-defined interface takes all input through parameters and gives all output through return values, not through global variables.
  • So you can use it without knowing its insides, test it alone, reuse it, and improve its insides while the interface stays the same.

The big picture

A subroutine's interface, its name, its parameters and its return value, is all the rest of the program needs to know about it. Arguments go in, one value comes back out, and nothing else should cross.

Key points

1The interface is the name, the parameters and the return value.
2Arguments are copied into the parameters in order; the result comes back through return.
3Printing is not returning: a function with no return statement gives back None.
4Local variables stay inside the subroutine, so a well-defined interface uses parameters and return values, never globals.

Worked example

Problem

A program needs the perimeter of a rectangle that is 6 long and 4 wide, and wants to use the answer in later code. Write the subroutine and the call, and say what the caller's variable holds.

⚠ Watch out

Thinking print and return do the same job. print shows a value on the screen, but only return passes it back, so the caller's variable ends up holding None.

🧠

Memory hook

Arguments in, one value out, nothing else crosses the line. Print is for people; return is for the program.

✓

Check yourself

Cover the page. Name the three parts of an interface, then say which part is missing when a subroutine only prints its answer.

Flashcards

(14)
What is a subroutine?
A named, self-contained block of code that carries out a specific task and can be called from other parts of the program.
What makes a subroutine well designed in terms of its job and its name?
It has one clear purpose (a single task), and its name describes that purpose.
What is the interface of a subroutine?
How it connects to the rest of the program: its name, the parameters it takes (what data, in what order, of what type) and the value it returns.
What is a parameter?
A variable listed in the brackets of the subroutine's definition. It receives the data the subroutine needs.
What is an argument?
A value supplied in a call. Arguments are copied into the parameters in order.
What is a return value?
The result a subroutine passes back to the code that called it. The caller can store it in a variable or use it directly in an expression.
In Python 3, how do you define a subroutine and pass a result back?
Define it with def and list the parameters in brackets after the name. Pass the result back with a return statement.
In Python 3, what does a function with no return statement give back?
None. A subroutine that only prints its result does not pass it back for the rest of the program to use.
What is the difference between printing a result and returning it?
Printing displays the value on the screen. Returning passes it back to the caller, which can then store it or use it.
What is a local variable?
A variable created inside a subroutine. It exists only while the subroutine runs and cannot be accessed from outside it.
What does a subroutine with a well-defined interface avoid?
Reading or changing global variables. All its input comes through parameters and all its output through return values.
What does a programmer need to know to use a subroutine with a clear interface?
Only its name, what parameters to pass and what it returns, not how the code inside works.
Why is a well-defined interface good for testing?
The subroutine can be tested on its own: call it with chosen arguments and compare the returned value with the expected result.
Name two benefits of subroutines with well-defined interfaces.
They are easier to reuse (in the same program or other programs), and different programmers can work on different subroutines.

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 posted

More Eduqas GCSE Computer Science topics

See the full Eduqas Computer Science curriculum →

How this lesson was checked. This Eduqas GCSE Computer Science (specification C500QS)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 16 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.