百文百鸡
for语法
for x in range(1, 33):
for y in range(1, 99):
z = 100 - x - y
if (z%0.5 == 0) and (3*x + 1*y + z/2 == 100):
print('公鸡:%s 母鸡:%s 小鸡:%s'%(x, y, z))
while 语法
x = 1
while x <33 :
y = 1
while y < 99:
if 0 < x :
z = 100 - x - y
if (z%0.5 == 0) and (3*x + y + 0.5*z == 100) :
print('公鸡:',x,'母鸡:',y,'小鸡:',z)
y += 1
x += 1
九九乘法表
a = 1
while a <10 :
b = 1
while b <= a :
print(a,'×',b,'=',a * b, end=" \t")
b += 1
print()
a += 1
变色星
a = 0
while a < 5:
b = 0
while b < 10 :
if b % 2 == 0:
print('☆', end=" ")
else:
print('★', end=" ")
if b % 10 == 9:
print()
b += 1
c = 10
while c < 20:
if c % 2 == 1:
print('☆', end=" ")
else:
print('★', end=" ")
if c % 10 == 9 :
print()
c += 1
if a % 10 == 9:
print()
a += 1