Python我的代码怎么了?

2024-04-25 15:18:43 发布

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

所以,我知道这很基本,但我发现了一个错误: 我该怎么修理这个?y、 是的

Traceback (most recent call last): File "/home/coding/Documents/Python Repository/2 - Numbers & math (Loan Calclator).py", line 40, in monthly_payment = float(loan_amount) * [0.05 * (1.0 + 0.05) * float(num_of_payments)] / [(1.0 + 0.05) * float(num_of_payments) - 1.0] TypeError: can't multiply sequence by non-int of type 'float'

#Loan Calculator

#Monthly Payments formula > M = L[i(1+i)n] / [(1+i)n-1]
# M = Month Payment
# L = Loan amount
# i = interest rate (int rate of 5%, i = 0.05)
# n = number of payments


print ('Hey there! Welcome to Johnny\'s Loan Bank!')

#just set variable
monthly_payment = 0

#Set how much money user will need
loan_input = input('So, how much would you like to lend? ')

#transform the input in a float
loan_amount = float(loan_input)


#Set number of months to pay
num_of_pay_input = input('And in how many months would you like to pay? ')

#transform value into a float
num_of_payments = float(num_of_pay_input)

print ('\nSo, you want to lend {0:.1f} in {1:.1f} payments'.format(loan_amount, num_of_payments))
print ('You should know that we work with an interest rate of 5%')

#Variable set to know the users decision
user_decision = input('Would you like to continue?: ')
print (user_decision)

if user_decision == 'y' or decision == 'yes':
    print ('loan_amount {0:.1f}'.format(loan_amount))
    print ('num_of_payments {0:.1f}'.format(num_of_payments))

Line 40>>>>     monthly_payment = float(loan_amount) * [0.05 * (1.0 + 0.05) * float(num_of_payments)] / [(1.0 + 0.05) * float(num_of_payments) - 1.0]

    print ('Ok, you\'ll get a loan of {0:.1f} and you gonna pay us in {1:.1f} months'.format(loan_amount, num_of_payments) + \
        ', thats gonna be {0:.1f} for month.'.format(monthly_payment))
else:
    print ('get off my bank')

Tags: oftoinyouformatinputfloatamount
1条回答
网友
1楼 · 发布于 2024-04-25 15:18:43

在你的队伍里:

    monthly_payment = float(loan_amount) * [0.05 * (1.0 + 0.05) * float(num_of_payments)] / [(1.0 + 0.05) * float(num_of_payments) - 1.0]

您使用方括号(在本例中用于创建列表)作为指定操作顺序的方法。这应该是()类型的括号。在

相关问题 更多 >

    热门问题