title: Understanding an example
body: <pre><code>def solve(numLegs, numHeads):
      for numChicks in range(0, numHeads + 1):
          numPigs = numHeads - numChicks
          totLegs = 4*numPigs + 2*numChicks
          if totLegs == numLegs:
              return [numPigs, numChicks]
      return [None, None]
  
  def barnYard(heads, legs):
      pigs, chickens = solve(legs, heads)
      if pigs == None:
          print "There is no solution."
      else:
          print 'Number of pigs: ', pigs
          print 'Number of Chickens: ', chickens
  </code></pre>
  
  <p>I'm learning Python and came across this example, can someone please explain in plain english (or pseudo-code) what this is doing line by line.</p>
  
  <p>Many thanks</p>