Module 6: Writing Your Own Functions
Organise code into reusable pieces. 9 Python coding games, each with short narrated videos and six levels.
This module is part of the full course. Unlock all 79 games for $9, or try Module 1 free.
- 38
Your first function: def and calling · Dance Floor
Teach a dancer a named routine. Then just call its name whenever you want it. - 39
How functions run · Relay Race
Pass the baton from function to function, and watch the code jump in and come back. - 40
Parameters: giving a function information · Pizza Oven
One function can serve every order. You just tell it what's on the pizza. - 41
Several inputs, defaults and names · Coffee Bar
Every customer wants something different. One function with a few options can handle them all. - 42
return: getting an answer back · Vending Machine
Money goes in, change comes back out. A function can hand an answer back to your program. - 43
print versus return · Quality Check
Inspector functions check each product. Only a returned answer ever reaches the sorting arm. - 44
Scope: where variables live · Hotel Rooms
Each function is a room. Whatever is left in a room can't be reached from the corridor, unless it's handed out. - 45
Splitting a program into functions · Assembly Line
A messy machine gets split into clean stations, each a function with its own job and its own test. - 46
Project: Calculator · Calculator
Your fourth real program: a working calculator, with a menu, and one function for each operation.