Posts

Showing posts with the label Python programs

Python program that show the use of a function

def solve(numlegs,numheads):  for numchiken in range(0, numheads+1):   numcow = numheads - numchiken   totallegs = 4 * numcow + 2 * numchiken   if totallegs==numlegs:    return [numcow,numchiken]  return [ None, None ] def barnyard():  numlegs = int(raw_input('Enter the number of legs:'))  numheads = int(raw_input('Enter the number of heads:'))  cow, chiken=solve(numlegs, numheads)  if cow == None:   print 'There is no solution'  else:   print 'There are ', cow, 'cows'   print 'And' ,chiken, 'chicks'