This module introduces splitting a Python program into focused modules.
- Difficulty: Advanced.
- Estimated Time: 45-60 minutes.
- Prerequisites:
02-core/file-io-basics,03-advanced/structs-and-classes. - Cross-Language Lens: Compare packages, projects, modules, and compilation units as different ways to scale beyond one file.
python example/main.py- Separating pricing, formatting, and orchestration across files.
- Importing reusable helpers from sibling modules.
- Keeping the entrypoint focused on flow.
- Treating module layout as part of design, not just organization.
- Putting every concern directly into
main.py. - Mixing calculations, formatting, and coordination in one function.
- Creating helper modules with hidden side effects at import time.
- Treating file structure as irrelevant to maintainability.
- Python keeps modularization flexible, so the comparison with C++ and C# highlights how little compile-time structure is enforced.
- Compared with Go or TypeScript, imports are lightweight but discipline matters more because the runtime lets you stay loose for longer.
- This module is best read as a design-boundary lesson, not just an import-syntax lesson.
- exercises/01.py: separate invoice calculations into focused helpers.
- exercises/02.py: build reusable command operations consumed by one caller.
- exercises/01.py
- Input: subtotal, discount percent, tax percent.
- Output: subtotal breakdown and final total.
- Edge cases: negative subtotal; percentages outside valid ranges.
- exercises/02.py
- Input: command name and integer operands.
- Output: result from a reusable operation registry.
- Edge cases: unsupported command; division by zero.
- I can separate coordination code from reusable modules.
- I can explain why a helper module exists.
- I can keep
main.pyfocused on flow rather than every detail. - I completed exercises/01.py.
- I completed exercises/02.py.