我看過類似的問題,但仍然無法弄清楚這一點。我絕對相信我在某個地方犯了一個非常愚蠢的錯誤,但我似乎無法找到它。混淆爲什麼我得到一個TypeError:'int'對象不可調用
對於此代碼。
class BankAccount:
def __init__(self, initial_balance):
self.balance = initial_balance
def deposit(self, amount):
self.deposit = amount
self.balance = self.balance + self.deposit
def withdraw(self, amount):
self.withdraw = amount
self.balance = self.balance - self.withdraw
self.fee = 5
self.total_fees = 0
if self.balance < 0:
self.balance = self.balance - self.fee
self.total_fees += self.fee
def get_balance(self):
current_balance = self.balance
return current_balance
def get_fees(self):
return self.total_fees
當我運行代碼的一切工作正常,當我運行這個
my_account = BankAccount(10)
my_account.withdraw(15)
my_account.deposit(20)
print my_account.get_balance(), my_account.get_fees()
但是,如果我做一個額外的呼叫撤回
my_account = BankAccount(10)
my_account.withdraw(15)
my_account.withdraw(15)
my_account.deposit(20)
print my_account.get_balance(), my_account.get_fees()
它拋出這個錯誤。
TypeError: 'int' object is not callable
我不明白爲什麼它能正常工作,直到我再打一個電話才能退出。請幫忙。