编写一个程序,让用户输入贷款金额和贷款期限的年数,并显示每月和总付款为每个利率从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 = '')
我不知道如何计算你需要的值,但据我所知,你需要利率从3%开始,每年增加1/8,也就是0.125,停在5。如果是这样,
numPy
会很有帮助。可以将interestRate
作为如下数组:^{} 给出您需要的数组,^{} 使5以上的所有值都等于5。你知道吗
相关问题 更多 >
编程相关推荐