Here's the output I'm getting when I run this:
Enter the starting salary:
150000
0.5 283387.2061567708 1
0.25 141693.6030783854 2
0.375 212540.4046175782 3
0.4375 247963.8053871746 4
0.46875 265675.50577197265 5
0.453125 256819.65557957362 6
0.4453125 252391.73048337406 7
0.44140625 250177.76793527429 8
0.439453125 249070.78666122444 9
0.4404296875 249624.2772982493 10
0.44091796875 249901.0226167618 11
logic satisfied
None
Here's the code I'm using to run it. I cannot for the life of me figure out why it's returning None instead of the tuple in the return statement. Any help sincerely appreciated.
def savings_finder():
user_input = float(input("Enter the starting salary:\n"))
y = savings_func(user_input,0, 0,1.0)
print(y)
savings, steps = y
print(savings,steps)
if savings == True:
print(f"Best savings rate: {savings} \nSteps in bisection search: {steps}")
else:
print("It is not possible to pay the down payment in three years.")
def savings_func(annual_salary,step, lower, upper):
#preset variables
semi_annual_raise = 0.07
investments_return = 0.04
downpayment = 250000
salary = annual_salary
#savings rate calculation (first step of bisection)
savings_rate = (lower+ upper) /2
#savings account that will be measured against downpayment, month for calculating correct incrementing of savings account
savings_account = 0
month = 0
while month <36:
savings_account += savings_rate* salary / 12 + savings_account * investments_return / 12
month += 1
if month%6 ==0:
salary+= salary*semi_annual_raise
#increment step
step +=1
# logic for evaluating next step of bisection search
print(savings_rate, savings_account, step)
if downpayment +100 >savings_account>downpayment-100:
print("logic satisfied")
return savings_rate, step
elif savings_account<downpayment-100 and savings_rate<=1.0:
savings_func(annual_salary,step,savings_rate,upper)
elif savings_account> downpayment+100 and savings_rate>=0:
savings_func(annual_salary,step,lower,savings_rate)
else:
return -1,0
savings_finder()