标签:buy,20,买百鸡,34,问题,range,plan,100,百元 From: https://www.cnblogs.com/leeyong49/p/16656421.html
# 三层循环来实现
buy_plan = 0
for g in range(20): # 最多买20只公鸡
for m in range(34): # 最多买34只母鸡
for x in range(300): # 最多买300只小鸡
if (g*5 + m*3 + x/3) == 100 and (g+m+x) == 100:
buy_plan +=1
print(f'第{buy_plan}种方案:公鸡{g}只, 母鸡{m}只, 小鸡{x}只')
# 用二层循环来实现
buy_plan = 0
for g in range(20): # 最多买20只公鸡
for m in range(34): # 最多买34只母鸡
x = (100 - g*5 -m*3) *3
if g+m+x ==100:
buy_plan += 1
print(f'第{buy_plan}种方案:公鸡{g}只, 母鸡{m}只, 小鸡{x}只')