title: Printing out the fibonacci series
body: <p>I am trying to write a simple Python program. It's supposed to return a a closure that returns successive fibonacci numbers:</p>
  
  <pre><code>def fibGen():
      n_1 = 0
      n_2 = 0 
      n = 1
      def fib():
          if n_1 ==0 and n_2 ==0:
              n_1 = 1
              return n
          else:
              n = n_1 + n_2
              n_2 = n_1
              n_1 = n  
              return n
      return fib
  
  f = fibGen()
  for i in range(0,10):
      print(f())
  </code></pre>
  
  <p>I get this error at run time:
  <code>UnboundLocalError: local variable 'n_1' referenced before assignment</code></p>
  
  <p>EDIT: In my original post, I had not included <code>n = 1</code> in the definition of <code>fibGen</code> but it was actually a typo. I would still get the same error anyway.</p>