The big idea: A function is a named block of code that does one job, can be given different inputs, and hands back a result.
Write it once, call it anywhere — and fix it in one place when it turns out to be wrong.
Parameter and argument: The parameter is the name in the definition — the placeholder.
The argument is the actual value passed in when it is called. Definition has parameters; calls supply arguments.
Free preview
This is the free notes preview
You're reading the free notes. Aimnova Pro unlocks the full study experience — and you can try it with your first topic free to keep:
- FlashcardsLock in vocabulary and key terms with spaced repetition.
- Practice questionsAnswer exam-style questions and get instant AI marking.
- Mock exams & past-paper vaultSit full mocks and see exactly how examiners award marks.
- Personalised study planA daily plan built around your exam date and weak areas.
Reusable
- One definition serves every place that needs the job done
- No copied blocks that then drift apart
- A fix applies everywhere at once
Maintainable
- Each function is small enough to understand completely
- A fault is traced to one function, not scanned for across a program
- It can be changed inside without touching anything that calls it
Testable and shareable
- A function can be tested on its own, with values chosen to break it
- Work can be split: different people write different functions
- Both only work because the boundary is clearly defined
The copy-paste argument: Copy a calculation into four places and you have four places to fix when it is wrong — and you will miss one.
Call a function in four places and there is one.
That is the strongest single argument for modularity, and the one to write down.
Modularisation is bigger than functions: It also means grouping related functions into modules or files — all the file handling in one place, all the calculations in another.
Same idea, one level up.
Never wonder what to study next
Get a personalized daily plan based on your exam date, progress, and weak areas. We'll tell you exactly what to review each day.
In through parameters
Out through return
Local stays inside
Globals, sparingly
A function with no return gives nothing back: If it only prints, the value cannot be used for anything else.
return the result and print it at the call if needed — a function that returns can be tested; one that only prints cannot.
How this is tested — you must define with parameters, return a value, and say why it is better than repeating the code. It comes up two ways:
Paper 2 — working with code
- Construct a function for a stated job, 3-5 marks
- Explain the benefits of modularisation
- Identify a scope error in given code
Paper 2 — the algorithmic-thinking question
- Explain why a program should be split up
- Reason about scope with no code shown
The classic trap: Writing a function that uses a global instead of a parameter, and prints instead of returning. It may work in the one place it was written, and it cannot be reused or tested anywhere else.
A program calculates a percentage in four different places. Write a function for it and explain why this is better.
Model answer plan
See the mark-by-mark plan — for / against / judgement, with marking guidance — in study mode.