Skip to content
Tutorials Center
My learning

Topics

Lesson 34 of 36 ยท Projects and Practice

Project: A Monthly Budget Simulator

Put your money skills together by building a small program that tracks income, spending, an emergency fund and a savings goal over twelve months.

In this project you will build a small simulator of one year of money. It starts with a monthly income, subtracts a budget with needs, wants and savings, includes a surprise expense, and tracks an emergency fund. Along the way you practice the skills from the whole track: budgeting, saving, planning and risk.

Everything here is invented. Replace the numbers with your own, and you have a personal tool.

The plan

The simulator follows these steps each month:

  1. Add income.
  2. Pay needs (rent, food, transport, bills).
  3. Pay wants (fun, eating out, subscriptions).
  4. Put the planned amount into savings.
  5. If something unexpected happens, pay it from the emergency fund first, then from the rest.
  6. Record the balance.
flowchart TD
    A["Income"] --> B["Needs"]
    B --> C["Wants"]
    C --> D["Savings goal"]
    D --> E["Surprise expense?"]
    E -- "yes" --> F["Use emergency fund"]
    E -- "no" --> G["Record balances"]
    F --> G

One month in the simulator.

Step 1: a basic year

The first program runs twelve months with fixed numbers. Read each line, then change a value and run it again.

Python A year of money, version 1

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

With these numbers each month's free amount is 150 after needs, wants and saving. The program is a simple model: it does not include interest, and it assumes the same numbers every month.

Step 2: add a surprise

Real months are not identical. Add a random surprise: some months bring a bill (repair, medical, broken device). The emergency fund exists for exactly this. The next version uses a fixed random seed so the result repeats each time you run it.

Python A year with surprises

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

If the fund is too small for a bill, the rest comes from cash. If cash also goes negative, you would have to borrow, which is the situation an emergency fund helps you avoid.

Step 3: make it yours

Your challenge is to extend the simulator. Pick any of these and write the code yourself:

  • Income changes: add a raise in month 7, or a month without income.
  • A debt: add a loan with a monthly payment, and let extra cash reduce it using ideas from paying off debt.
  • Interest: let savings earn 3% a year (0.25% a month).
  • Run it 1,000 times and count how many years leave you with negative cash for different fund sizes.

Here is a short template for the last idea using the same model, written compactly.

Python How big should the emergency fund be?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The simulation shows a pattern: more emergency savings makes borrowing less likely, but the benefit has diminishing returns. That is why experts suggest a target such as three to six months of essentials rather than an infinite fund.

What you learned

By building this you used several track ideas at once: a budget with needs, wants and saving, an emergency fund, and the use of simulation to understand risk. You also saw that a model is only as good as its assumptions, so change them and compare.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does the simulator pay surprise bills from the emergency fund first?

    An emergency fund exists to absorb unexpected costs without borrowing.
  2. 2. In the first program, income 2,400, needs 1,300, wants 650 and saving 300 leave a free amount of

    2,400 โˆ’ 1,300 โˆ’ 650 โˆ’ 300 = 150.
  3. 3. Why use a random seed in a simulation you want to repeat?

    A fixed seed gives the same random sequence every time.
  4. 4. A model's results depend most on

    Change the assumptions and the results change.

Summary

  • A simulator combines income, needs, wants, savings and surprises over time.
  • An emergency fund absorbs shocks that would otherwise become debt.
  • Simulation with random events shows how likely different outcomes are.
  • A model is only as good as its assumptions; adjust them to match your life.

Next: Project: A Debt Payoff Planner