# Barn yard example: counting heads and legs
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
barnYard(20,56)
Expected result is 8 and 12 I think, but it returns 'There is no solution'. What am I doing wrong?
I'm just starting with programming, so please be nice ... :)