python 全站开发 2(15课)

内容 代码实现,百钱买百鸡

1问题公鸡5文一只,母鸡3文一只,小鸡3只一文。用100文买100只鸡,要求必须有公鸡,母鸡,小鸡

2思考分析,设公鸡为x,母鸡为y,小鸡为z

                  则,界定x.y.z的取值范围

             5x <100  则 ==  0<x<20

             3y<100则= =0<y<33 

             z =100-x-y   

代码实现

for  x  in range(1,20):

    for y in range(1,33):

扫描二维码关注公众号,回复: 857830 查看本文章

         z = 100 -x -y

         if  (z * 3 = =0) and (x * 5  + y * 3 + 2/3 = =100):

         s = "公鸡 :(%d只:母鸡:%d只: 小鸡:%d只:"(x.y.z)

         print(s)

猜你喜欢

转载自www.cnblogs.com/asdccc/p/9040326.html