写一个等额本息的还款计算器
时间: 2024-12-13 22:23:49 浏览: 8
等额本息还款计算器是一种用于计算贷款分期付款的工具,它按照每月偿还本金和利息相等的方式来分配还款额度。假设你有一个贷款总额、年利率以及贷款期限,下面是一个简单的Python函数示例:
```python
def equal_payment_calculator(total_amount, annual_interest_rate, loan_term_in_years):
# 将利率转换为月利率
monthly_interest_rate = annual_interest_rate / 12
# 总期数(月)
total_months = loan_term_in_years * 12
# 每月应还金额的公式
monthly_payment = (total_amount * monthly_interest_rate) / (1 - (1 + monthly_interest_rate)**(-total_months))
return {
"总借款金额": total_amount,
"年利率": annual_interest_rate,
"贷款期限(年)": loan_term_in_years,
"月利率": monthly_interest_rate,
"每月还款额": round(monthly_payment, 2),
"总还款额": round(monthly_payment * total_months, 2)
}
# 示例使用
loan_details = equal_payment_calculator(100000, 5.5 / 100, 5)
for key, value in loan_details.items():
print(f"{key}: {value}")
阅读全文