DEV Community

pwong09
pwong09

Posted on

4

A Terminal Budget Program with Python!

I've been working on the Computer Science Pro track on Codecademy for the past 4 weeks. To finish the "Intro to Programming" section, I had to do an open-ended portfolio project.

The requirements were:

  1. Build a terminal program using Python
  2. Add at least one interactive feature using input()
  3. Use Git version control
  4. Use the command line and file nav
  5. Write a technical blog post on the project (this post!)

I brainstormed a bit about what I wanted to make, and ultimately I chose to write a simple budgeting calculator. I had just finished a One-Month Expenses Tracking challenge with my friends, so with money on mind, I came up with all these different financial calculator ideas.

Budgeting has been foremost in my mind because I'm currently unemployed and re-skilling & up-skilling in order to transition my career (previously in chocolate making) into the tech sector.

(I know, I know, most people do the opposite. They want to get /out/ of tech, and chocolate seems like a nice way to go! Anyone want to trade?)

Anyway, I started by jotting down what information I would need to build a budget. Income after taxes was an easy first thought. How can you build a budget with no income? Then, I thought, what is the biggest expense for most people? Housing. It would be tough to guess how much someone spends on housing, so it would be better if they provided that info!

In my first iteration, I started with a basic function to return the amount someone would have left over after housing. And I thought, "Hey, don't forget to save some of that income!" There are lots of ways to assume a basic budget, but a good general rule is to save 20%, so I started there.

The initial commit

The next thought I had was, what if housing was really expensive relative to your income? What if you can't save or you can't even afford that much house?

I made a second function, and things started getting a little chaotic. I thought, wow there must be an easier way to do this. Also, I haven't even started using Classes and OOP, and I'm supposed to include that in my program somewhere.

I ended up scrapping my entire first 2 commits, and re-writing my budget function into a Budget class. I knew I wanted to make a subclass for people who have higher savings goals. I'm a big believer in saving more whenever possible. Building up personal savings is a really important practice for me - and it still is even though I don't have an income anymore.

Finally using what I learned about Classes

So after making sure the Budget class worked properly, I created the SuperSaver subclass. It was fun to work out the save_spend method, and overall I'm glad I make my first initial mistakes because, hey that's how I learn right?

Adjusting methods was a challenge, but I figured it out I think!

I showed my terminal program to my partner later, and she recommended that I add more inputs for other expenses, like debt payments, car payments, health insurance, etc.
I'll get around to that someday - for now I'm pretty thrilled by what I've done.

Terminal program

Take a look and let me know how the code can be improved:
https://github.com/pwong09/portfolio-project

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

Best practices for optimal infrastructure performance with Magento

Running a Magento store? Struggling with performance bottlenecks? Join us and get actionable insights and real-world strategies to keep your store fast and reliable.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️