title: Python nested functions variable scoping
body: <p>I've read almost all the other questions about the topic, but my code still doesn't work.</p>
  
  <p>I think I'm missing something about python variable scope.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>PRICE_RANGES = {
                  64:(25, 0.35),
                  32:(13, 0.40),
                  16:(7, 0.45),
                  8:(4, 0.5)
                  }
  
  def get_order_total(quantity):
      global PRICE_RANGES
      _total = 0
      _i = PRICE_RANGES.iterkeys()
      def recurse(_i):
          try:
              key = _i.next()
              if quantity % key != quantity:
                  _total += PRICE_RANGES[key][0]
              return recurse(_i) 
          except StopIteration:
              return (key, quantity % key)
  
      res = recurse(_i)
  </code></pre>
  
  <p>And I get </p>
  
  <blockquote>
    <p>"global name '_total' is not defined"</p>
  </blockquote>
  
  <p>I know the problem is on the <code>_total</code> assignment, but I can't understand why.
  Shouldn't <code>recurse()</code> have access to the parent function's variables?</p>
  
  <p>Can someone explain to me what I'm missing about python variable scope?</p>