2016-11-04 64 views
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) 

回答

1

withdraw方法BankAccount缺少量:

class BankAccount(object): 
    def __init__(self): 
     pass 

    def withdraw(self): # <--- ADD THE AMOUNT HERE 
     pass 

同样与deposit方法

+0

非常感谢。错过了 – sammyukavi