Community Market Price Logger (Day 1 of 30 Days of Python)
Source: Dev.to
Intro
Day 1 of my 30 Days of Python: a tiny CLI that logs community market prices in Nigeria, prints prices with the naira symbol (₦), and shows the difference from the last recorded values.
- Prompts for market name and date
- Takes current prices for Garri and Rice
- Stores values in a dictionary
- Prints prices with ₦ and thousands separators
- Compares against the last record and shows the difference
Implementation notes
- Unicode/Encoding – Using the naira sign as
\u20A6ensures it renders even if the editor font has issues. UTF‑8 saves render ₦ fine in VS Code/GitHub. - f‑Strings + Quotes – Avoid nested double quotes inside f‑strings when indexing a dict. Use single quotes for keys:
{food_items['garri']}. This fixes syntax errors. - Dictionary Keys vs Index – Access by key strings, not numeric indices, to avoid
KeyError. - Safe Numeric Input – Convert
input()tointso you can format with:,(e.g.,₦1,800). - Tiny UX Wins – Prefix prompts with ₦ so users know the expected unit; add blank lines for readable output.
Future ideas
- Input validation (reject non‑numeric input gracefully)
- Persist daily logs to CSV/JSON
- Track more items and compute min/max/average over time
- Add a
--marketand--dateflag for quick logging
Call to Action
If you’re building African‑focused tools with Python, drop feedback or ideas. Stars and forks are welcome!