title: Why is my variable is unbound in one inner function but not the other?
body: <p>In the code below, why does the first version of <code>say</code> work but the second version throws &quot;local variable 'running_high' referenced before assignment&quot;?</p>
  <pre><code>def announce_highest(who, last_score=0, running_high=0):
      
      assert who == 0 or who == 1, 'The who argument should indicate a player.'
      ''' this one works
      def say(*scores):
          assert len(scores) == 2
          gain = scores[who] - last_score 
          if gain &gt; running_high:
              print(gain, &quot;point(s)! That's the biggest gain yet for Player&quot;, who)
              return announce_highest(who, scores[who], gain)
          return announce_highest(who, scores[who], running_high)
      return say
      '''
      # this one errors &quot;local variable 'running_high' referenced 
      # before assignment&quot;
      def say(*scores): 
          gain = scores[who] - last_score
          if gain &gt; running_high:
              running_high = scores[who]-last_score            
              print(gain,&quot;point(s)! That's the biggest gain yet for Player&quot;,who) 
              return announce_highest(who, scores[who], gain)   
          return announce_highest(who,scores[who],running_high)
      return say
  </code></pre>