运行简单的ATM程序时收到错误消息

时间:2015-12-12 20:56:08

标签: python-3.x

我是编程方面的新手,迫不及待地开始像你们这样做。

我使用类为python 3.5语言编写了这个简单的ATM程序,它给了我一个错误信息 ...(' init ()只需1个参数(2个给定)',),... 请问我在下面的程序中写错了什么。

class BankAccount(object):
  def __init__(self):
    self.balance = 90

  def deposit(self, ammount):
    self.balance = self.balance + ammount
    return self.balance

  def withdrawal (self,  ammount):
    if  self.balance < ammount:
        return 'invalid transaction'
    self.balance = self.balance - ammount
    return self.balance

class MinimumBalanceAccount(BankAccount):
  def __init__(self):
      BankAccount.__init__(self)
      self.minimum_balance = self.balance

  def withdraw(self, amount):

    if self.balance - amount < self.minimum_balance:
        print ('Sorry, minimum balance must be maintained.')
    else:
        BankAccount.withdraw(self, amount)
        self.balance = self.balance - ammount
    return self.balance

如果我能得到答复,我真的很高兴。 感谢

1 个答案:

答案 0 :(得分:0)

Python遵循严格的缩进,因此如果不遵循正确的缩进过程,您的代码将无法运行。在这里您编写的代码对我来说很好,没有任何错误:

class BankAccount(object):
    def init(self): self.balance = 90

def deposit(self, ammount):
    self.balance = self.balance + ammount
    return self.balance

def withdrawal (self, ammount):
    if self.balance < ammount:
        return 'invalid transaction'
        self.balance = self.balance - ammount
        return self.balance

class MinimumBalanceAccount(BankAccount):
    def init(self):
        BankAccount.init(self)
        self.minimum_balance = self.balance

def withdraw(self, amount):
    if self.balance - amount < self.minimum_balance:
        print ('Sorry, minimum balance must be maintained.')
    else:
        BankAccount.withdraw(self, amount)
        self.balance = self.balance - ammount
    return self.balance