第一次接触python。并且练习百元买百鸡的一个写法。
在执行过程中会遇到
IndentationError: unindent does not match any outer indentation level
TabError: inconsistent use of tabs and spaces in indentation
经查资料python有严格的格式要求,所以大家在写代码的过程中一定要注意格式。
通过计算机实现以下计算:
一只公鸡5元,一只母鸡3元,三只小鸡1元。
目前有100元需要购买以上3种鸡,每一种都必须有,总共有多少种购买的方法?
我们通过以下python代码实现
# coding=UTF-8 for x in range(1,20): for y in range(1,33): z = 100-x-y if(z%3==0)and(x*5+y*3+z/3==100): s="公鸡:%d只:母鸡:%d只:小鸡:%d只"%(x,y,z) print(s)
原文:https://www.cnblogs.com/mdlb/p/12360033.html