Skip to content

Week 1 · Python and your developer toolkit

Assignment: a café expense report

Turn a month of café expenses into a clear report a business owner can act on, and publish it to GitHub.

AssignmentEstimated time: 4 h

The brief

The owner of a small café tracks expenses by hand. Every month they spend an evening adding up receipts, and they still can't tell where the money goes or which payments needed a second look. They've asked you for a script that does it for them.

Due: before the week 1 checkpoint. Work: individually. You may discuss approaches, but write your own code. Follow the AI tools policy: you must be able to explain every line.

Starter data

Create week-01/expenses.py in your fde-course repository and start with this data. Amounts are in rupees:

week-01/expenses.py
expenses = [
    {"item": "Coffee beans", "category": "Supplies", "amount": 18500},
    {"item": "Milk", "category": "Supplies", "amount": 9200},
    {"item": "Electricity bill", "category": "Utilities", "amount": 27400},
    {"item": "Espresso machine repair", "category": "Equipment", "amount": 35000},
    {"item": "Paper cups", "category": "Supplies", "amount": 6300},
    {"item": "Internet", "category": "Utilities", "amount": 4500},
    {"item": "Social media ads", "category": "Marketing", "amount": 12000},
    {"item": "Barista wages", "category": "Staff", "amount": 60000},
    {"item": "Sugar and syrups", "category": "Supplies", "amount": 7800},
    {"item": "Flyers", "category": "Marketing", "amount": 3500},
]

APPROVAL_LIMIT = 25000

Requirements

Your script must print a report that shows:

  1. The number of expenses recorded.
  2. The total spent, formatted with commas.
  3. The total for each category. Build a dictionary of category totals with a loop. Don't type the categories by hand: your code must still work if the café adds a new category next month.
  4. The largest single expense, with its name and amount.
  5. Every expense over APPROVAL_LIMIT, and how many there are. The owner wants to double-check these.

Use only what you've learned this week: variables, lists, dictionaries, if and for loops.

Expected output

Your layout can differ, but the numbers must match:

Cafe expense report
Expenses recorded: 10
Total spent: Rs 184,200

By category:
  Supplies   Rs  41,800
  Utilities  Rs  31,900
  Equipment  Rs  35,000
  Marketing  Rs  15,500
  Staff      Rs  60,000

Largest expense: Barista wages (Rs 60,000)

Needs approval (over Rs 25,000): 3
  - Electricity bill: Rs 27,400
  - Espresso machine repair: Rs 35,000
  - Barista wages: Rs 60,000

Acceptance criteria

Your submission is complete when all of these are true. We'll check each one.

  • python3 week-01/expenses.py runs without errors from the root of your repository.
  • Every number in the output matches the expected output above.
  • Category totals are calculated by a loop, not typed in by hand.
  • Adding a new expense with a new category to the list changes the report correctly, with no other code changes.
  • Changing APPROVAL_LIMIT to 10000 changes the approval list correctly.
  • Your repository has at least three commits for this assignment, each with a clear message.
  • README.md has a section for this script: what it does and how to run it.
Stuck?Show hints
  • Category totals: start with an empty dictionary, totals = {}. For each expense, if its category is already a key, add to it. If not, create the key. Look up dict.get() for a shorter way to do this.
  • Largest expense: start by assuming the first expense is the largest, then loop and replace it whenever you find a bigger one.
  • Lining up columns: f-strings can pad values. f"{category:<10}" left-aligns text in 10 characters, and f"{amount:>7,}" right-aligns a number in 7.

Stretch tasks

Optional, and they won't affect your grade:

  • Sort the categories from largest to smallest total.
  • Show percentages: what share of the total each category takes, to one decimal place.
  • Add a monthly budget for each category in a second dictionary, and flag any category that went over.

How to submit

  1. Commit your work and push it to your fde-course repository with git push.
  2. Check on GitHub that week-01/expenses.py and your updated README are there.
  3. Share the link to your repository with your instructor.

Finished this lesson?