title: "local variable referenced before assignment"
body: <p>I come from a land of heavy Java and PHP experience so when it comes to Python much of the rules do not make sense to me.</p>
  
  <p>I have a recursive Fibonacci function below that spits out the error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\Nic\workspace\lab8\src\Main.py", line 26, in &lt;module&gt;
      print fibcount(27),"took",calls,"calls."
    File "C:\Users\Nic\workspace\lab8\src\Main.py", line 19, in fibcount
      calls += 1
  UnboundLocalError: local variable 'calls' referenced before assignment
  </code></pre>
  
  <p><strong>Here is my code:</strong></p>
  
  <pre><code>calls = 0
  
  def fibcount(n):
      calls += 1
      if n &lt; 2:
          return (1,1)
      f1,c1 = fibcount(n-1)
      f2,c2 = fibcount(n-2)
      return (f1+f2,c1+c2+1)
  
  print fibcount(27),"took",calls,"calls."
  </code></pre>
  
  <p>In Java this would obviously work because calls is a global variable in respect to the function <code>fibcount()</code> so it confuses me that calls is somehow not in scope.</p>
  
  <p>What am I doing wrong?</p>