# budget.py, M2 solution: a budget categorizer.
# It loops over a list of expenses, DECIDES a size for each, and tallies a total.
# Each expense is a DICTIONARY, the exact shape data arrives in from an API (you'll see it in M4).
# Run in Colab (paste into a cell) or with:  python budget.py

# --- 1. The data: a LIST of DICTIONARIES -------------------------------------
# A list holds many things in order, in [ ].
# A dictionary holds labelled values in { }, as "key": value pairs.
expenses = [
    {"item": "Coffee",         "amount": 4.50},
    {"item": "Groceries",      "amount": 62.00},
    {"item": "Bus ticket",     "amount": 2.75},
    {"item": "New headphones", "amount": 89.99},
    {"item": "Lunch",          "amount": 13.25},
]

# --- 2. Running totals we'll fill in as we loop ------------------------------
total = 0
big_count = 0

# --- 3. Loop over every expense and DECIDE a size ----------------------------
for expense in expenses:
    amount = expense["amount"]      # read a value out of the dictionary by its key
    total += amount                 # add it to the running total (total = total + amount)

    if amount < 5:                  # a decision, using a comparison
        size = "small "
    elif amount < 50:               # "else if", checked only if the first was False
        size = "medium "
    else:                           # everything else
        size = "big "
        big_count += 1

    expense["size"] = size          # add the decision back INTO the dictionary as a new key
    print(f"{expense['item']:<16} ${amount:>6.2f}  → {size}")

# --- 4. Report, using len() to count the list --------------------------------
print(f"\nYou spent ${total:.2f} across {len(expenses)} things.")
print(f"{big_count} of them were big purchases.")

# --- 5. Each record is now API-shaped data -----------------------------------
# This is exactly what a list of records looks like coming back from an API:
print(f"\nFirst record as data: {expenses[0]}")
