编辑代码

# coding:utf-8
#JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 
# 定义初始参数
initial_fund = 10**8  # 初始启动资金 C
profit_rate = 0.052  # 利润率 p
total_insured = 10**5  # 总投保人数
payout_per_person = 20000  # 每人赔付金额 u
hair_loss_rate = 0.05  # 三级脱发率
premium_per_person = 1000  # 每人保费
years = 10  # 运行年数

# 计算每年的赔付人数
annual_payout_count = (total_insured * hair_loss_rate) // years  # 向下取整 q1
final_year_payout_count = total_insured * hair_loss_rate - (years - 1) * annual_payout_count  # 第十年赔付人数 q2

# 初始化变量
current_fund = initial_fund
year = 1

# 模拟每年的资金流动
while year <= years:
    if year < 10:
        # 计算当年的赔付金额
        payout_amount = annual_payout_count * payout_per_person
    else:
        # 第十年的赔付金额
        payout_amount = final_year_payout_count * payout_per_person
    
    # 计算当年的利息收入
    interest_income = current_fund * profit_rate
    
    # 更新当前资金
    current_fund = current_fund + interest_income - payout_amount
    
    # 输出当年的资金情况
    print(f"Year {year}: Current Fund = {current_fund:.2f}")
    
    # 进入下一年
    year += 1

# 输出最终结果
print(f"Final Fund after {years} years: {current_fund:.2f}")