BankSystem 和我想贷款,但它抛出一个 TypeError

BankSystem and I want to take loan but it throws a TypeError

我试图从 BankSystem 贷款,但它抛出一个错误并说列表对象不可调用,我想请用户输入 100 欧元到 300 欧元之间的价格,如果这个数字更高那是不接受的,但如果该金额是 100 欧元和 300 欧元,则可以接受:

import datetime
class BankSystem:
    total_deposit = 0
    total_withdraw = 0
    def __init__(self,name,accountNumber,salary):
        self.name = name
        self.accountNumber = accountNumber
        self.salary = salary
        self.withdraw_history = []
        self.deposit_history = []
        self.take_loan = []
    def description(self):
        print("Name is: " , self.name)
        print("AccountNumber: " , self.accountNumber)
        print("Salary: " , self.salary)
    def deposit(self,deposit):
        self.salary = self.salary + deposit 
        self.deposit_history.append(deposit)
        self.total_deposit += 1
    def withdraw(self,withdraw):
        self.salary = self.salary - withdraw
        self.withdraw_history.append(deposit)
        self.total_withdraw += 1
    def transaction_history(self):
        print("You have withdraw", self.withdraw_history , "On date:" , datetime.datetime.now())
        print("You have deposit" , self.deposit_history , "On date:" , datetime.datetime.now())
    def take_loan(self):
        answer = int(input("Enter the amount of loan who would you like to take between - 100Euros and 300 Euros: "))
        if answer > 300:
            print("Choose between 100 - 300 Euros not more")
        else:
            print("You have taken out for loan" , answer)
            self.take_loan.append(answer)
            
        
bank = BankSystem("Bill" , 42919502 , 4000)
bank.take_loan()   

删除行 self.take_loan = [].

您正在用空列表对象覆盖 take_loan() 函数,然后尝试调用它。

self.take_loan = []

那就麻烦了。它将标识符 take_loan 设置为空白列表,并在 def take_loan(): [...].

之后执行

所以当你 运行 bank.take_loan() 时,这就像试图调用空列表,这确实不是错误消息所指示的可调用。