0
我想調用方法SavingsAccount.withdraw(600)
但每次我得到一個異常TypeError: withdraw takes exactly 1 arguement(2 given)
。我該如何解決?請指教。從子方法的Python調用父方法
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)
非常感謝。錯過了 – sammyukavi