total_cost = float(input('房子总价: ')) # 获取房子总价
annual_salary = float(input('输入你的年薪: ')) # 获取输入的年薪
portion_saved = int(input('存钱比例 例如:60: '))/100 # 获取输入的存钱比例
semi_annual_raise = int(input('涨薪比例 例如:7: '))/100 # 每半年薪资涨幅
portion_down_payment = 0.30 # 首付比例 30%
interest_rate = 0.0225 # 年化利率
month = 0 # 月份数
current_savings = 0 # 当前存款
month_salary = annual_salary / 12 # 月收入
while current_savings < total_cost * portion_down_payment:
month += 1
current_savings += current_savings * interest_rate / 12 + month_salary * portion_saved
if month % 6 == 0: # 每6个月涨薪一次
month_salary = month_salary * (1 + semi_annual_raise)
print(f'首付需要{month}月')