python房贷模拟器
时间: 2023-11-16 19:00:35 浏览: 229
horse-race-sim
以下是Python房贷模拟器的代码实现:
```python
# -*- coding: utf-8 -*-
# Python房贷模拟器
def calculate_loan(principal, rate, years):
"""
计算房贷每月还款额
:param principal: 贷款本金
:param rate: 贷款利率
:param years: 贷款年限
:return: 每月还款额
"""
months = years * 12
monthly_rate = rate / 12
payment = principal * monthly_rate * (1 + monthly_rate) ** months / ((1 + monthly_rate) ** months - 1)
return payment
if __name__ == '__main__':
principal = float(input("请输入贷款本金(万元):"))
rate = float(input("请输入贷款利率(%):")) / 100
years = int(input("请输入贷款年限(年):"))
payment = calculate_loan(principal, rate, years)
print("每月还款额为:%.2f 元" % payment)
```
阅读全文