# 问题:公鸡5文钱一只,母鸡3文钱一只,小鸡3只一文钱,用100文钱买100只鸡,其中公鸡,母鸡,小鸡都必须要有,问公鸡,母鸡,小鸡要买多少只刚好凑足100文钱? ‘‘‘ 公鸡 < 20 母鸡 < 33 小鸡 < 300 ‘‘‘ for cock in range(1,20): for hen in range(1,33): for chick in range(1,300): sum = cock + hen + chick pay = cock*5 + hen*3 + chick/3 if sum == 100 and pay == 100: print("公鸡%s只 母鸡%s只 小鸡%s只"%(cock,hen,chick))
原文地址:https://www.cnblogs.com/chenglei0520/p/10177879.html
时间: 2024-10-08 10:04:06