Your task
Build a dictionary of completed sales per period without a third-party package. Explain the expected output before running the code.
Hint
Read with csv.DictReader so column names are explicit. CSV values are strings until converted. Keep parsing failures visible.
Worked solution
April 30000 and May 40000 cents. Sorting YYYY-MM strings works for this validated format, not arbitrary date labels.
import csv
with open('retail-orders.csv',newline='',encoding='utf-8') as f:
rows=list(csv.DictReader(f))
from collections import defaultdict
monthly=defaultdict(int)
for r in rows:
if r['status']=='completed': monthly[r['period']]+=int(r['net_cents'])
assert dict(monthly)=={'2026-04':30000,'2026-05':40000}
print(sorted(monthly.items()))Extend the test
Change one input in a disposable copy and predict which check should fail. Restore the original before comparing results.
Try the activity before reading its reference. Keep your sources, commands and assumptions with your work. Companion activities are unsaved self-practice and do not award a certificate or change lesson progress.