#This part asks for the user input
annual_salary = float(input("Enter your annual salary:"))
#Declaring all the variables
total_cost = 1000000
High = 1.0
Low = 0.0
portion_saved = (High +Low)/2.0
semi_annual_raise = 0.07
r = 0.04 #annual investment return
portion_down_payment = 0.25
num_guesses = 0
epsilon = 100
total_saving = 0.0
months = 0
#Calculations next
while abs(total_cost - total_saving) >= epsilon:
num_guesses += 1
total_saving = 0.0
while total_saving < (total_cost*portion_down_payment):
monthly_salary = annual_salary/12
monthly_saving = monthly_salary*portion_saved
total_saving += (monthly_saving + total_saving*r/12)
months += 1
if months%6 == 0:
annual_salary += annual_salary*semi_annual_raise
if (total_saving < total_cost):
Low = portion_saved
else:
High = portion_saved
portion_saved = (Low+High)/2.0
print("Best savings rate:", portion_saved)
print("Number of steps:", num_guesses)
Но код входит в бесконечное число l oop. При проверке с использованием команды печати выясняется, что переменная part_saved принимает значение 1,0 на каждой итерации. Но я не могу понять, почему это происходит. Может кто-нибудь помочь?