编写一个程序,该程序使用户可以输入贷款金额和贷款期限(以年为单位),并显示从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 = '')