首页 > 代码库 > python-百钱买白鸡

python-百钱买白鸡

经典题目:有100文钱,要买100只鸡,公鸡5文一只,母鸡3文一只,小鸡三只一文,问公鸡母鸡小鸡各多少只?

 

#/usr/bin/python
#-*-encoding:utf-8-*-

# x + y + z = 100
# 5x + 3y + z/3 = 100
for x in range(1, 20):
    for y in range(1, 33):
        z = 100 - y - x
        if z % 3 == 0 and 5 * x + 3 * y + z / 3 == 100:
            print 公鸡:, x, , 母鸡:, y, , 小鸡:, z, 

 

python-百钱买白鸡