title: Why does it say (in python) "UnboundLocalError: local variable 'yes' referenced before assignment" when I already defined the variable?
body: <p>This is my code:</p>
  
  <pre><code>from random import randint
  
  ant1 = 1
  ant2 = 2
  ant3 = 3
  ant4 = 4
  cntNum = 0
  no = 0
  yes = 0
  
  def antMove(antNum):
      randomNum = randint(0,3)
      if randomNum == antNum:
          yes += 1
      else:
          print("No")   
  
  while cntNum &lt; 20:
      antMove(ant1)
      antMove(ant2)
      antMove(ant3)
      antMove(ant4)
      cntNum = cntNum + 1
  
  if cntNum == 20:
      print(yes)    
  </code></pre>