python - 贷款金额及贷款期限程序
问题描述
编写一个程序,让用户以年数为单位输入贷款金额和贷款期限,并显示从 3% 到 5% 的每个利率的每月和总还款额,增量为 1/8。每月供款和总供款的计算公式如下:
我需要 1/8 增量方面的帮助。我想到了一个 for 循环,但 Python 不允许浮点数。我研究了一下,发现了一个叫做 numpy 的东西,但我还没有学会。有没有办法做到这一点?
这是我到目前为止所拥有的:
monthlyPay = 0
total = 0
#Prompt the user to enter loan amount and loan period in years
loanAmount = float(input("Enter loan amount: $"))
years = int(input("Enter loan period in years: "))
#Display Table Header
print("Interest\tMonthly Pay\tTotal")
#Display Table Results
for yr in range(0,years):
interestRate = 3/(100*12)
#Calculate Monthly Payment
monthlyPay = loanAmount*interestRate/(1-(1/((1+interestRate)**(years*12))))
#Calculate Total Payment
total = monthlyPay * years * 12
print(format(interestRate, '.3f'), '%\t\t', format(monthlyPay, '.2f'),\
'\t\t', format(total, '.2f'), sep = '')
解决方案
推荐阅读
- java - 在项目中使用 log4j Logger 通过 Maven 添加
- javascript - 如何使用酶的 setProps() 测试组件
- android - 华为 Mate 20 Pro 上的 React Native 开发者菜单
- python - 我有一个带有 urls-pdfs 的列表,我想将它们本地保存到我的电脑
- python - 使用 Flask API 返回“仍在加载”响应
- javascript - Mocha.Testfunction 中 [mochawesome] addContext 的问题
- python - 对某些列进行分组并总结 CSV 中的另一列
- java - 如何使用千分尺指定我想在spring-boot中使用的指标的白名单
- wordpress - WordPress - 为插件输出 URL 添加重写规则
- c# - 如何定义不需要参数的参数集(PS cmdlet)?