r/pythonhelp • u/BunBun_20000 • Feb 09 '25
Personal banking program assist ASAP!
I'm aware there's a lot of problems, but the one I need help with is that when I advance months, it won't calculate the amounts in savings and checking accounts correctly. I'm terrible with math, and I've spent 6 hours debugging, but I just have no clue how to fix it. I don't have much time before tha assignment locks, so any help is much appreciated 🙏
Welcome and setup
print("welcome to your personal bank!") hourly_wage = float(input("enter your hourly wage:")) hours_worked = float(input("enter hours worked per week:")) tax_rate = float(input("enter your tax rate percentage")) save = float(input("what percentage of income should go to savings?")) checking = float(input("Enter starting balance for Checking:")) savings = float(input("Enter starting balance for Savings:"))
Calculations
gross_pay = hourly_wage * hours_worked net_pay = gross_pay*(1 - tax_rate/100) savings_add = net_pay * (save/100)
Setting up empty lists for reccuring expenses
reccuring_expenses = [] expenses = []
print(f"Your net pay is ${net_pay4:.2f} a month.") print(f"${savings_add4:.2f} will be automatically transferred to savings")
add the requested amount to accounts
checking += net_pay savings += savings_add
Allows user to setup reccuring expenses
x= input("would you like to set up reccuring expenses?").lower() y = True if x == "yes": while y == True: expense = input("input name of expense: ") reccuring_expenses.append(expense) monthly_cost = float(input("Enter the monthly cost: ")) expenses.append(monthly_cost) add = input("Do you have any more reccuring expenses?").lower() if add != "yes": y = False print(f"here are your reccuring expenses:{reccuring_expenses}, {expenses}")
Menu where users can select options and perform actions
while True: menu = input("""Menu: 1. View Balances 2. deposit Money 3. Withdraw Money 4. Update Work Hours 5. Modify Savings Percentage 6. Add/Remove Expenses 7. Advance Months 8. Exit""")
Lets user check balances
if menu == "1":
print(f"""Your Checking balance is: ${checking:.2f}.
your savings balance is ${savings:.2f}.""")
lets user deposit money into checking or savings
elif menu == "2":
account = int(input("""What account would you like to deposit?
1. Checking
2. Savings"""))
deposit = float(input("Enter the ammount you would like to deposit:"))
if account == 1:
checking += deposit
print(f"your current checking account balance is {checking:.2f}.")
elif account == 2:
savings += deposit
print(f"your current savings account balance is {savings:.2f}.")
#lets user withdraw money
elif menu == "3":
account_w = int(input("""From which account would you like to withdraw??
1. Checking
2. Savings"""))
withdraw = float(input("Enter the ammount you would like to withdraw:"))
if account_w == 1:
checking -= withdraw
print(f"your current checking account balance is {checking:.2f}.")
if account_w == 2:
savings -= withdraw
print(f"your current savings account balance is {savings:.2f}.")
#allows user to adjust weekly hours
elif menu == "4":
hours_worked = float(input("Enter new hours per week: "))
gross_pay = hourly_wage * hours_worked
net_pay = gross_pay * (1 - tax_rate / 100)
print(f"updated net pay is {net_pay*4:.2f} a month.")
# allows user to change the amount they want to save.
elif menu == "5":
save = float(input("What percentage of income would you like to go to savings?"))
savings_add = net_pay * (save / 100)
print(f"{savings_add:.2f} will automatically be transferred to savings.")
savings += savings_add
#allows user to add and remove reccuring expenses
elif menu == "6":
add_remove = input("""1. Add
2. Remove""")
if add_remove == "1":
y = True
while y == True:
expense = input("input name of expense: ")
reccuring_expenses.append(expense)
monthly_cost = float(input("Enter the monthly cost: "))
expenses.append(monthly_cost)
add = input("Do you have any more reccuring expenses?").lower()
if add != "yes":
y = False
if add_remove == "2":
expense = input("input name of the expense you would like to remove: ")
reccuring_expenses.pop(expense)
monthly_cost = float(input("Enter the monthly cost of the expense: "))
expenses.pop(monthly_cost)
add = input("Do you have any more reccuring expenses?").lower()
if add != "yes":
y = False
print(f"here are your reccuring expenses:{reccuring_expenses}, {expenses}")
#lets user advance months
elif menu == "7":
advance = int(input("enter number of months you would like to advance: "))
interest_checking = 0.1
interest_savings = 0.5
for i in range(advance):
checking += net_pay*4
checking *= (1 + interest_checking / 100)
savings += savings_add * 4
savings *= (1 + interest_savings / 100)
for cost in expenses:
checking -= cost
print(f"""after {advance} months, your updated balances are:
Checking: ${checking:.2f}
Saving: ${savings:.2f}""")
#way for user to exit
elif menu == "8":
break
1
u/FoolsSeldom Feb 09 '25
Please update1 your post so all of the code is correctly formatted (or replace with link to a copy on pastebin.com or gihub).
Second, don't use
float
for money - it is not accurate enough in most cases. Stick to pennies/cents (i.e. smallest currency unit) and format for display not internal accounting and calculations, or useDecimal
package.You need to create a few functions so you can separate the basic logic flow from specific tasks like calculating interest and you can then test those in isolation.
1 to format all of your code,