Functions define reusable operations; modules organize related definitions into importable files. Keep inputs, outputs and side effects visible.
Before you begin
Use a local Python environment and a small file or script. Read the error output carefully and keep sample records fictional.
Work through the idea
Begin with a tiny input whose answer you can calculate by hand. Write the expected result, implement the operation and compare the actual result. Add an empty or invalid input and state its handling explicitly. Keep input parsing separate from the main calculation where practical.
- Define a function contract
- Move related functions into a module
- Keep execution code distinct from reusable definitions
Practice task
Create a text-summary module and a small script that calls it.
Check your result
Importing the module should not unexpectedly read private files or begin an interactive session.
A mistake to avoid
Avoid mutable default arguments when you expect a fresh collection for every call.
Keep a review note
Save the inputs or scenario, your reasoning and the result you checked. Explain one assumption and one case that needs more work. Revise the exercise after feedback and distinguish what you demonstrated from what remains untested.
Official reference for further study
Explore the related learning path · Choose another worksheet
