问题:公鸡5文钱一只,母鸡3文钱一只,小鸡3只一文钱,用100文钱买100只鸡,其中公鸡,母鸡,小鸡都必须要有,问公鸡,母鸡,小鸡要买多少只刚好凑足100文钱?
1 for x in range(0,100//5): 2 for y in range(0,100//3): 3 for z in range(0,100): 4 if x + y + z ==100 and x*5+y*3+z/3 == 100: 5 print("公鸡:%s母鸡:%s小鸡:%s"%(x,y,z))
九九乘法表
for i in range(1,10): string = "" for c in range(1,i+1): string += str(i) + "*" + str(c) + "=" + str(i * c) + " " print(string) #第二种写法 for i in range(1,10): for c in range(1,i+1): print(str(i) + "*" + str(c) + "=" + str(i * c) + " ",end="") print(" ",end=""