[英]BankSystem and I want to take loan but it throws a TypeError
我试图从 BankSystem 贷款,但它抛出一个错误,并说列表 object 不可调用,我想要求用户输入 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 = []
。
您正在使用空列表 object 覆盖take_loan()
function,然后尝试调用它。
self.take_loan = []
那是在惹麻烦。 它将标识符take_loan
设置为空白列表,并在def take_loan(): [...]
之后执行。
因此,当您运行bank.take_loan()
时,就像尝试调用空列表一样,它确实不是可调用的,如错误消息所示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.