One simple calculator, taken from first design to best practice.
A programming kata in Jupyter notebooks. The benefit comes from the process, not the result: copy the challenge, attempt it yourself, then compare against a fully annotated walkthrough.
The walkthrough
Follow the notebooks in order — each revisits the same calculator with higher standards. Open any notebook directly in Google Colab (no install) or read it in nbviewer.
- calculator_design.ipynbThe challenge and the design — start hereColabnbviewer
- calculator_good_development.ipynbA good first working version, development styleColabnbviewer
- calculator_good_production.ipynbThe same version, cleaned up for productionColabnbviewer
- calculator_better.ipynbBetter structure: functions, validation, exceptionsColabnbviewer
- calculator_better_production.ipynbThe better version, production-readyColabnbviewer
- calculator_best.ipynbThe best-practice version — the full walkthrough with notesColabnbviewer
- calculator_eval.ipynbEvaluating the versions against each otherColabnbviewer
The ten best practices
The habits the walkthrough applies, version by version:
- Use a code repository — small, frequent commits
- Follow style guidelines (PEP 8)
- Correct broken code immediately — exceptions, validation, testing
- Use PyPI instead of reinventing —
import it
- Use the right data types and structures
- Write readable code — meaningful names and comments
- Create readable documentation — docstrings
- Use virtual environments
- Avoid anti-patterns — specific imports, specific exceptions
- Follow the Zen of Python — try
import this