1条回答 默认 最新
- 辉煌仪奇 2021-10-27 09:42关注
参考代码
def monthlyPayment(principal, year_rate, year_duration): monthly_rate = year_rate / (12 * 100) # 将4.9转换为0.049,并转换为月利率 month_amounts = year_duration * 12 # 每月月供 monthly_payment = (principal * monthly_rate * (1 + monthly_rate) ** month_amounts) / ( (1 + monthly_rate) ** month_amounts - 1) # 总利息 total_interest_payable = monthly_payment * month_amounts - principal print('-----------------------------------') print('应付利息总额为 %.2f ' % total_interest_payable) for i in range(1, month_amounts + 1): # 每月应还利息 monthly_interest_payable = principal * monthly_rate * ( (1 + monthly_rate) ** month_amounts - (1 + monthly_rate) ** (i - 1)) / ( (1 + monthly_rate) ** month_amounts - 1) # 每月应还本金 monthly_principal_payable = principal * monthly_rate * (1 + monthly_rate) ** (i - 1) / ( (1 + monthly_rate) ** month_amounts - 1) # 每月利息占比 monthly_interest_percentage = monthly_interest_payable * 100 / monthly_payment print('-----------------------------------') print(f'{i} 月付款 : {round(monthly_payment, 2)} (每月应还利息: {round(monthly_interest_payable, 2)} 每月应还本金: {round(monthly_principal_payable, 2)})') print(f'{i} 月利息占比 {monthly_interest_percentage}') return if __name__ == '__main__': principal = int(input('请输入您的贷款金额:')) year_rate = float(input('请输入年度债务利率:(输入 4.9就是 4.9%)')) year_duration = int(input('请输入债务年度期限:')) monthlyPayment(principal, year_rate, year_duration)
有帮助请采纳,有问题继续交流,你的采纳是对我回答的最大的肯定和动力
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥40 图书信息管理系统程序编写
- ¥15 7-1 jmu-java-m02-使用二维数组存储多元线性方程组
- ¥20 Qcustomplot缩小曲线形状问题
- ¥15 企业资源规划ERP沙盘模拟
- ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
- ¥15 前端echarts坐标轴问题
- ¥15 ad5933的I2C
- ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
- ¥15 数学建模求思路及代码
- ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题