python2.7 百钱买百鸡

#!/usr/bin/python
#coding=utf-8
#for buy chicks
print '公鸡5元一只,母鸡3元一只,小鸡一元3只,百钱买百鸡有以下方案'
cocks=100//5
hens=100//3
chicks=100*3
for i in range(0,cocks+1):
  for j in range(0,hens+1):
    for k in range(0,chicks,3):
      sum=i+j+k
      total=5*i+3*j+int(k/3)
      if sum==100 and int(total)==100:
        print '公鸡:'+str(i)+'\t' +'母鸡:'+str(j)+'\t'+'小鸡:'+str(k)

结果如下:

 

posted @ 2019-07-12 17:35  Dragon-海  阅读(2576)  评论(0编辑  收藏  举报