title: Python variables outside function
body: <p>I'm trying to access the counter variable in my function, why doesn't it work and how do I resolve it? </p>
  
  <p>Relevant code: </p>
  
  <pre><code>sum = 0
  counter = 0
  
  def newFibo(a, b) :
      if(counter &gt; 4000000) :
          return
  
      c = a + b
  
      sum += c
      counter +=1
      newFibo(b,c)
  
  newFibo(1,2)
  print(sum)
  </code></pre>
  
  <p>error: "local variable 'counter' referenced before assignment"</p>