Procedures and Functions1 / 17
What is a subroutine?
As programs grow, copying the same code in multiple places is a nightmare — change one copy and forget the other and you've introduced a bug.
Subroutines (also called subprograms) solve this: give a block of code a name, and call it whenever you need it.
There are two types:
- Procedure — runs a block of code, does NOT return a value
- Function — runs a block of code and returns a value
```python
# Procedure — just does something
def show_menu():
print("1: Play game")
print("2: High scores")
print("3: Quit")
show_menu() # call it once
# ... later ...
show_menu() # call it again — same code, no duplication
```
AQA spec says: *procedures* execute code without returning a value; *functions* return a value. Make sure you know which is which.