AttributeError帮助!

Sou*_*urD 0 python

  class Account:
  def __init__(self, initial):
      self.balance = initial
      def deposit(self, amt):
          self.balance = self.balance + amt
      def withdraw(self,amt):
          self.balance = self.balance - amt
      def getbalance(self):
          return self.balance

a = Account(1000.00)
a.deposit(550.23)
a.deposit(100)
a.withdraw(50)

print a.getbalance()
Run Code Online (Sandbox Code Playgroud)

运行此代码时出现此错误.NameError:帐户实例没有属性"存款"

Mat*_*hen 5

class Account:
    def __init__(self, initial):
        self.balance = initial
    def deposit(self, amt):
        self.balance = self.balance + amt
    def withdraw(self,amt):
        self.balance = self.balance - amt
    def getbalance(self):
        return self.balance
Run Code Online (Sandbox Code Playgroud)

你定义它们的方式,它们是__init__方法的本地,因此是无用的.