我想调用方法SavingsAccount.withdraw(600)
,但每次收到异常TypeError: withdraw takes exactly 1 arguement(2 given)
。我该如何解决?请指教。
class BankAccount(object):
def __init__(self):
pass
def withdraw(self):
pass
def deposit(self):
pass
class SavingsAccount(BankAccount):
def __init__(self):
self.balance = 500
def deposit(self, amount):
if (amount < 0):
return "Invalid deposit amount"
else:
self.balance += amount
return self.balance
def withdraw(self, amount):
if ((self.balance - amount) > 0) and ((self.balance - amount) < 500):
return "Cannot withdraw beyond the minimum account balance"
elif (self.balance - amount) < 0:
return "Cannot withdraw beyond the current account balance"
elif amount < 0:
return "Invalid withdraw amount"
else:
self.balance -= amount
return self.balance
class CurrentAccount(BankAccount):
def __init__(self, balance=0):
super(CurrentAccount, self).__init__()
def deposit(self, amount):
return super(CurrentAccount, self).deposit(amount)
def withdraw(self, amount):
return super(CurrentAccount, self).withdraw(amount)
x = CurrentAccount();
print x.withdraw(600)
答案 0 :(得分:1)
withdraw
中的BankAccount
方法缺少金额:
class BankAccount(object):
def __init__(self):
pass
def withdraw(self): # <--- ADD THE AMOUNT HERE
pass
与deposit
方法相同