Here’s a piece of code I just finished. I might add some more things but at a good stopping point. I like to think that I am getting better. I made a real effort to include notes and full names so others can figure out what I am doing. Eventually I want to build a portfolio on GitHub.
#[0] #[1] #[2]
Copy and paste it in and let me know what you think. This is my 6th project so if anyone has improvement suggestions please let me know
# Budget Calculator based on 50/30/20
# A fun project to play with
# Define each calculation to make it modular, organized, and reusable
def savings_calculation(income):
return income * 0.2
def yearly_savings_calculation(income):
return (income * 12) * 0.2
def emergency_savings_calculation(income):
return (income * 0.8) * 6
def emergency_savings_months_calculation(income):
return ((income * 0.8) * 6) / (income * 0.2)
def essential_expenses_calculation(income):
return income * 0.5
def non_essential_expenses_calculation(income):
return income * 0.3
def inflation_loss_calculation(income):
return (income * 12) * 0.06
def calculate_debt_payment(debt, income):
return debt / (income * 0.2)
# Introduction Output
print("This is a simple program that explores what a 50/30/30 budget would look like for you.")
print("This is not intended as financial advice, only a educational tool.")
print(" ")
# Get input for monthly income
# loop to insure number input only
while True:
try:
income = int(input("What is your monthly take home income? $"))
except ValueError:
print("Invalid response. Please enter a number only.")
else:
break
# Calculations
savings = savings_calculation(income)
yearly_savings = yearly_savings_calculation(income)
emergency_savings = emergency_savings_calculation(income)
emergency_savings_months = emergency_savings_months_calculation(income)
essential_expenses = essential_expenses_calculation(income)
non_essential_expenses = non_essential_expenses_calculation(income)
inflation_loss = inflation_loss_calculation(income)
# Output print
print(" ")
print("Your monthly expenses for essential expenses should not exceed: ${:.2f}".format(essential_expenses))
print("Essential expenses would be food, housing, utilities, things of this nature.")
print(" ")
print("Your monthly spend on non-essential expenses should not exceed: ${:.2f}".format(non_essential_expenses))
print("Non-essential expenses would be cable tv, subscription services, fun and entertainment, things of this nature")
print(" ")
print("Your monthly target for savings and debt payment: ${:.2f}".format(savings))
print(" ")
print("You will save: ${:.2f} this year by following this plan".format(yearly_savings))
print("Your loss in purchasing power due to inflation this year is: ${:.2f}".format(inflation_loss))
print(" ")
print("Your emergency savings goal is: ${:.2f}".format(emergency_savings))
print("It will take you {:.0f} months to reach this goal by using your monthly target for savings and debt payment".format(emergency_savings_months))
print(" ")
# Debt input and tree
# loop to insure yes or no input only
while True:
try:
debt_question = input("Do you have debt? yes or no? ")
if debt_question.lower() == 'no':
print("Great Job!")
elif debt_question.lower() == 'yes':
debt = int(input("How much total debt do you have? $"))
debt_payment = calculate_debt_payment(debt, income)
print("It will take you {:.0f} months to pay this off using your monthly target for savings and debt payment.".format(debt_payment))
else:
raise ValueError("Invalid response. Please enter yes or no only.")
except ValueError as e:
print(e)
else:
break
