1、for循环里套着for循环
打印一个菱形 难度三颗星
*
*
from sys import stdout
for i in range(4):
for j in range(2 - i + 1):
stdout.write(' ')
for k in range(2 * i + 1):
stdout.write('*')
print
for i in range(3):
for j in range(i + 1):
stdout.write(' ')
for k in range(4 - 2 * i + 1):
stdout.write('*')
print
for i in range(1, 5):
print(' ' * (4 - i), end="")
for j in range(1, 2 * i):
print('*', end="")
print()
for i in range(3, 0, -1):
print(' ' * (4 - i), end="")
for j in range(1, 2 * i):
print('*', end="")
print()
for i in range(1,5):
print(' '*(4-i),end="")
for j in range(1,2*i):
print('*',end="")
print()
2、两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。
好厉害的思维:
逝者如斯,成人的世界凭实力和能力说话
for a in ['x','y','z']:
for b in ['x','y','z']:
for c in ['x','y','z']:
if
(a!=b)and(a!=c)and(c!=b)and(a!='x')and(c!='x')and(c!='z'):
print('a--%s,b--%s,c--%s'%(a,b,c))