title: Keep getting NameError from class variable?
body: <p>So I'm trying to fully understand Python OOP by creating a class but I'm really confused about this error I keep getting. Still learning so please try to understand my beginner situation here.</p>
  <pre><code>  class Investor:
  
      def __init__(self, name, principle, returns):
          self.name = name
          self.principle = principle
          self.returns = returns 
  
      def info(self):
          return '{} {}'.format(self.name, self.principle)
  
      def deposit(self):
          global deposit_amount
  
          deposit_amount = float(input('Amount: '))
          return deposit_amount + self.principle + self.returns
  
      def withdraw(self):
          global withdraw_amount
  
          withdraw_amount = float(input('Withdraw amount: '))
          return self.principle + self.returns + deposit_amount - withdraw_amount
  
      def balance(self):
          if deposit_amount &gt; 0 or withdraw_amount &gt; 0:
              return self.principle + self.returns + deposit_amount - withdraw_amount
          else:
              return self.principle + self.returns
  
  
  
      
  
  
  investor1 = Investor('John', 5000, 0)
  
  while True:
      prompt = input('What would you like to do?\n')
      if prompt == 'Balance':
          try:
              print(investor1.balance())
          except ValueError:
              print(investor1.info())
  
  
      elif prompt == 'Deposit':
          print(investor1.deposit())
  
      elif prompt == 'Withdraw':
          print(investor1.withdraw())
  </code></pre>
  <p>Output:</p>
  <pre><code>What would you like to do?
  </code></pre>
  <p>When I first enter <code>Deposit</code> and then <code>Withdraw</code> and <em><strong>then</strong></em> <code>Balance</code> the code works perfectly fine.</p>
  <p>However, when I input <code>Balance</code> first, I get the following error:</p>
  <pre><code>return self.principle + self.returns + deposit_amount - withdraw_amount
  NameError: name 'deposit_amount' is not defined
   
  </code></pre>
  <p>Any help, folks?</p>