A budget tracker
The problem
Build a program that keeps track of income and spending from typed commands, and gives a clear report by category.
Requirements
- Commands add income, add an expense with a category, and show a report
- Each transaction is stored as a dictionary or an object in a list
- A report shows the total for each category and the overall balance, in neat columns
- Bad commands and bad numbers give a clear message and do not stop the program
- The logic is in small functions, with no printing inside the calculation functions
- Tests with assert cover totals and edge cases such as an empty list
Technologies
- Python
- Dictionaries and lists
- Functions
- Exceptions
- f-strings
Step by step
- Decide on the shape of one transaction, and write one by hand.
- Write a function that adds a transaction to the list, and test it with assert.
- Write functions that work out the balance and the total for each category.
- Write the report function, using format codes to line up the columns.
- Write the loop that reads a command and calls the right function.
- Add try and except around converting numbers, with helpful messages.
- Add a dictionary of commands in place of a chain of if statements.
- Test unusual inputs: no transactions, unknown categories and negative amounts.
Expected result
A program you can run and type commands into, which never crashes on bad input and always shows correct totals.
How it is evaluated
- Totals are correct, including for an empty list
- Bad input is handled with a clear message
- Functions are small and do one job each
- The report lines up correctly
- Tests exist and pass
Ways to improve it
- Save the transactions to a file with the json module
- Add monthly budgets and warnings
- Show a simple text bar chart for each category