基本抵押计算

2024-10-01 04:59:15 发布

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

所以我是一个初学者,我试图做一个简单的抵押计算器。这是我的代码:

L=input('Enter desired Loan amount: ')
I=input('Enter Interest Rate: ')
N=input('Enter time length of loan in months: ')

MonthlyPayments= [float(L)*float(I)*(1+float(I))*float(N)]/((1+float(I))*float(N)-1)


print('Your Monthly Payments will be {0:.2f}'.format(MonthlyPayments))`

我得到一个错误:不支持/:“list”和“float”的操作数类型


Tags: of代码inputratetimefloatamountlength
3条回答

这里:

MonthlyPayments = [float(L)*float(I)*(1+float(I))*float(N)]/((1+float(I))*float(N)-1)

本部分:

^{pr2}$

提供“list”数据类型。将[]替换为()

首先使用方括号将创建一个列表,它可能不是您想要的。另外,为了避免不断转换,您可以(并且应该)用您期望的类型包装输入调用。在

从你的示例代码来看,我会这样写:

L=float(input('Enter desired Loan amount: '))
I=float(input('Enter Interest Rate: '))
N=float(input('Enter time length of loan in months: '))

MonthlyPayments = (L*I*(1+I)*N)/((1+I)*N-1)

print('Your Monthly Payments will be {0:.2f}'.format(MonthlyPayments))

这也使它更容易阅读

 MonthlyPayments= (float(L)*float(I)*(1+float(I))*float(N))/((1+float(I))*float(N)-1)

“[”和“]”创建列表。在

相关问题 更多 >