Calculate savings with Python!
Andrew Rawson
Posted on November 26, 2024
I started learning coding and programming about a month and a half ago on Codecademy and decided to pursue a CS certification. This is my first ever project and I actually started it before I got the project assignment for Codecademy's CS Course. I fleshed it out to give it a bit of terminal eye candy before publishing it.
A bit of backstory before I get into the nitty gritty of the codebase. I am a lifelong gamer. I started on the Atari 2600 when I was a wee boy and stuck with consoles all the way up to the Series X. Back in 2022 Valve announced the Steam Deck and reminded me that I had signed up for a Steam account back in college and kind of just forgot about it, because I never had a machine worthy of playing games.
Fast forward back to 2022. I decided I really wanted a Steam Deck, and bought a laptop to revive my Steam account while waiting for my turn in the reservation queue. After I got my hands on the Deck, I realized what kind of monster Linux had become in the decade since I had last even touched it. So that inspired me to do what every gamer nerd ultimately does, if they are of the PC variety. I build my own computer.
I knew from the offset that it was going to be a Linux box, I just had to get it put together first. After spending many many dollars acquiring and assembling parts, I had my beast, and it was ready for Linux.
I started learning Bash and RPi and Linux. Then I wanted more. I knew Linux was comprised of bash, Python and C. So I signed up for Codecademy, tried the free 7 days for the paid methods, and kept it. Which brings us to today.
I started writing Python functions as I started learning Python to flex my mental muscles outside of the course work. I work at a bank, so as I made my way through Intermediate and Advanced Python, I started putting together a calculator. First it was just loans, then it was certificates of deposit. Then I was learning how to use JSON and lambdas to create a table for money market dividend rates.
I got it to where it could calculate all three formulas before even starting the CS Cert course, so when I got to this assignment, I decided to add visuals and other sugar to the syntax to make it a proper terminal game/app.
The code uses classes and objects to do most of the work, save for the JSON/lambda shenanigans. There are a total of 5 classes in a family setup with a parent/child/grandchild relationship. The first class is the BankProduct class. It handles the flow of the rest of the app by passing the user to either the LoanProduct or DepositProduct logic depending on their first choice. If the chosen product is a savings product, the DepositProduct class repeats the same methods used by the BankProduct class to direct the user to either the Certificate logic or the MoneyMarket logic depending on how they answer the following prompt.
The app is built for people who work with finances and would need a quick way to calculate these figures. So the expectation is that they would know at the very least the amount, interest rate, and term of the product. With this in mind, the products will ask for that information from the user and then do the math. The exact information required varies but some form of input is requested. For example, the user may enter the name of the loan product as the calculations work the same for all loan types.
At the same time the names for "Certificate" and "Money Market" are static and so they are not required to be entered. And in the case of the Money Market account the dividends are dependent on the deposit balance, so the user does not have to enter the rate in that case, as the JSON has the tiered rates for money market accounts stored. As rates fluctuate with the market, a savvy user could edit the dividend rates in the JSON to reflect those changes.
After providing the requested three or four pieces of information, the program does the calculations using algorithms scripted in, using the information provided by the user as the variables. The program will return all the information about the product (name, balance, rate, term) as well as monthly payment, total interest, and total balance paid for loans and total dividends and new balance for savings accounts.
After returning the requested information, it will ask if the user wants to do another calculation. If the answer is yes, it will loop back to start, if no, it will terminate.
Feel free to view the GitHub repo here.
It was a lot of fun to write and I can't wait to see what I come up with next. Programming is fun!
Posted on November 26, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.