for i inrange(100): for j inrange(100): for k inrange(100): number = i + j +k price = i*5 + j*3 + k*(1/3) if (number <= 100) & (price <= 100) & (k % 3 == 0): print("There are %dck, %d hen, and %d chick" % (i,j,k))
鸡兔同笼问题
1 2 3 4 5 6 7 8 9
# 今有鸡兔同笼,上有三十五头,下有九十四足,问鸡兔各几只?
for i inrange(1,35): for j inrange(1,35): if (i*2 + j*4) == 94and (i + j == 35): print("There are %d chickens,and %d rabbits" % (i,j))
result = [(i,j) for i inrange(1,35) for j inrange(1,35) if (i*2 + j*4) == 94and i + j ==35] print(result)