如何在贷款计算器中获得每月分期付款?

2024-05-16 00:10:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我是新来的编码,我不能找出错误在我的作业

请看下面的代码和帮助

#LOAN CALCULATOR ask for help
monthlyPayment = 0
loanAmount=input('please enter the loan amount \n')
##make the returned input a numeric value
float(loanAmount)
interestRate=input('please enter the interest rate \n')
##make the returned input a numeric value
float(interestRate)
numOfpay=input('please enter the number of installments \n')
##make the returned input a numeric value
float(numOfpay)
##monthlypayment = (L*(i*(1+i)**n)/((1+i)**(n)-1))
monthlyPayment= (loanAmount*(interestRate*(1+interestRate)**numOfpay) / ((1+interestRate)**(numOfpay)-1)) 

print(monthlyPayment)

我希望每月分期付款,但我要这个

TypeError: unsupported operand type(s) for +: 'int' and 'str'


Tags: the编码forinputmakevaluefloatenter
1条回答
网友
1楼 · 发布于 2024-05-16 00:10:56

当您试图将一个值转换为浮点(或任何数据类型)时,必须将它重新赋给同一个变量

float(loanAmount) 应该是 loanAmount = float(loanAmount)

这将确保它转换了数据类型

相关问题 更多 >