Skip to content

M2 solution

The expected, fully-commented artifact for M2's lab. Peek only after you've tried the lab: the win is writing it yourself.

File What it is
budget.py The budget categorizer, fully commented: a list of dictionaries → a for loop → an if/elif/else decision → a running total, then the data shown API-shaped.

Run it

In Google Colab (today's way): open the file, copy its contents into a cell, press ▶ Run.

On your own computer (from M3 onward, once Python is installed):

python budget.py

How this was verified

Run with Python 3 before shipping. Output observed (note this 5-item version totals \$172.49; the lab uses a shorter 4-item list that totals \$82.50):

Coffee           $  4.50  → small 
Groceries        $ 62.00  → big 
Bus ticket       $  2.75  → small 
New headphones   $ 89.99  → big 
Lunch            $ 13.25  → medium 

You spent $172.49 across 5 things.
2 of them were big purchases.

First record as data: {'item': 'Coffee', 'amount': 4.5, 'size': 'small '}