Python bankaccount类错误

时间:2016-01-12 19:08:11

标签: python-2.7

class BankAccount: 
    def __init__(self,  balance, MinimumBalanceAccount):
        """Creates an account with the given balance."""
        self.money = balance 
        self.penalty = 0
        self.balance = balance
        self.MInimumBalanceAccount = MinimumBalanceAccount

    def deposit(self, amount):
        """Deposits the amount into the account."""
        self.money += amount
        return self.money

    def withdraw(self, amount):
        if self.money - amount < 0:
           self.money -= amount+5
           self.penalty += 5

        else:
           self.money -= amount
        return self.money


    def get_balance(self):
        """Returns the current balance in the account."""
        return self.money

    def get_fees(self):
        """Returns the total fees ever deducted from the account."""
        return self.penalty

class MinimumBalanceAccountsub_class(BankAccount):
    def __init__(self, name, minimum):
       self.name = name
       self.minimum = minimum

我正在尝试运行该程序,但显示内部错误时出现以下语法:内部错误:

>  runTests aborted: TestOutcomeEvent(handled=False, test=, result=,
> outcome='error', exc_info=(, TypeError('__init__() takes exactly 3
> arguments (2 given)',), ), reason=None, expected=False,
> shortLabel=None, longLabel=None) is not JSON serializable

任何人都可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

  

TypeError(' init ()正好接受3个参数(2given)'),)

发生错误是因为在构造函数中未指定第三个参数 money 。以下应解决问题

  

def __init__(self, money, balance, MinimumBalanceAccount): """Creates an account with the given balance.""" self.money = balance self.penalty = 0 self.balance = balance self.MInimumBalanceAccount = MinimumBalanceAccount