Level 2 / Project 09 - Config Driven Calculator¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| Concept | This project | — | Quiz | Flashcards | Diagram | Browser |
Estimated time: 40 minutes
Focus¶
- read behavior from json config
Why this project exists¶
This project gives you level-appropriate practice in a realistic operations context. Goal: run the baseline, alter behavior, break one assumption, recover safely, and explain the fix.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
cd <repo-root>/projects/level-2/09-config-driven-calculator
python project.py --config data/sample_input.txt --list
python project.py --config data/sample_input.txt --op add --a 10 --b 5
python project.py --config data/sample_input.txt --op divide --a 10 --b 0
pytest -q
Expected terminal output¶
Expected artifacts¶
- Calculation results on stdout
- Passing tests
- Updated
notes.md
Checkpoint: Baseline code runs and all tests pass. Commit your work before continuing.
Alter it (required) — Extension¶
- Add a
sqrtoperation that only uses the--aoperand. - Add a
--chainmode:--chain "add:5,multiply:2"starting from--a. - Use
settings.precisionfrom the config to control decimal places.
Break it (required) — Core¶
- Pass a config file with missing "operations" key.
- Compute
2 ** 1000— does the result overflow? - Pass non-numeric values for
--aor--b.
Fix it (required) — Core¶
- Add
config.setdefaultfor missing keys. - Check for overflow/infinity in calculate results.
- Wrap float() conversion in try/except in batch mode.
Checkpoint: All modifications done, tests still pass. Good time to review your changes.
Explain it (teach-back)¶
- Why is config-driven design useful vs hard-coding operations?
- How does
dict.setdefaultdiffer fromdict.get? - What is the Strategy pattern and how does this project resemble it?
- When would you use JSON config files in real applications?
Mastery check¶
You can move on when you can: - load and validate JSON config from memory, - add a new operation by editing only the config file, - explain the difference between hard-coded and config-driven behaviour, - implement operation chaining from scratch.
Related Concepts¶
| ← Prev | Home | Next → |
|---|---|---|