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'

Comments

Popular posts from this blog

Tip of the Day # 13

Governor Generals of Pakistan

Tip of the Day# 12