頭金 ( コード内 ) から 100 ドル以内の 36 か月間rate_approx
の節約 ( コード内 ) になる節約率 ( コード内 ) を見つけようとしています。current_savings
down_payment
for
ループ内で毎回ループを実行して、36 か月間while
の成長を表しています。current_savings
次に、その貯蓄率が高すぎるか低すぎるかによって調整されたら、新しい貯蓄savings_rate
をして 36 か月の期間で試してみたいと思います。そのため、前のループ実行からcurrent_savings
開始していないことを確認するためにリセットし、再試行します。current_savings
for
house_price = float(1000000)
down_payment = float(house_price*0.25)
high = float(1)
low = float(0)
rate_approx = float((low + high)/2)
salary = float(150000)
monthly_salary = float(salary/12)
monthly_contribution = float(monthly_salary*rate_approx)
semi_annual_raise = float(1.07)
APR = float(1.04)
current_savings = 0
while abs(current_savings - down_payment) > 100:
current_savings = 0
for n in range(35):
current_savings = float((current_savings + monthly_contribution) * APR)
if n > 0 and n%6 == 0:
monthly_salary = float(monthly_salary * semi_annual_raise)
monthly_contribution = float(monthly_salary*rate_approx)
if current_savings < down_payment + 100:
current_savings = 0
low = rate_approx
rate_approx = (low + high)/2
print("low")
print("savings rate:",rate_approx)
elif current_savings > down_payment + 100:
current_savings = 0
high = rate_approx
rate_approx = (low + high)/2
print("high")
print("savings rate:",rate_approx)
else:
break
print("savings rate:", float(rate_approx))
print("savings:", float(current_savings))
current_savings
プログラムは、最終的な値がますます大きくなる貯蓄率をどんどん小さくし続けているのはなぜですか?