Functions and reusable programs
Package clear operations as functions, pass data explicitly, return useful results, and organize code into modules.
Conditions, loops, and collections. You can write working scripts.
Write focused, reusable functions with explicit inputs, meaningful return values, default arguments, and proper module organization without side effects on import.
Read in order, or jump to what you need.
Every lesson builds on the one before it. Open any lesson to read the explanation, run the examples, and try the practice challenges.
- 04.01Defining functions4 min
Name a useful operation and trace how arguments enter and results leave a function call.
- 04.02Parameters and scope4 min
Pass arguments clearly, understand local names, and avoid accidental sharing through defaults.
- 04.03Return values and pure functions4 min
Build predictable transformations with complete return paths and clear boundaries around side effects.
- 04.04Flexible arguments and functional tools4 min
Design functions that accept variable inputs, pass behavior as a value, and choose readable transformations.
- 04.05Recursion and problem solving4 min
Solve problems that contain smaller versions of themselves, trace the call stack, and know when iteration is safer.
- 04.06Modules and imports4 min
Use the standard library and organize your own functions into files that can be imported safely.
- 04.07Project: A number guessing gameProject4 min
Turn loops, conditions, functions, and input validation into a small game with testable rules.
- 04.08Project: Snake, Water, GunProject4 min
Build a best-of-five Snake, Water, Gun game with pure rule functions, validated input, and tests that never depend on luck.
Ready to move on?
Separate a calculation logic from input/output display, import your function from a second file, and call it without running unwanted code on import.
Open the module self-check