繁体   English   中英

Python - 我的代码有什么问题?

[英]Python - What's wrong with my code?

所以,我知道这是非常基本的,但我收到了这个错误:我能做些什么来修复这个?

回溯(最近一次调用):文件“/home/coding/Documents/Python Repository/2 - Numbers & math (Loan Calculator).py”,第 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] 类型错误:不能将序列乘以“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')

在您的行中:

    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]

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM