*************
1, 打印一个正方形:
length=int(input('>>>'))
for hith in range(length):
for width in range(length):
print(" * ",end="")
print()
中空正方形:
length=int(input('>>>'))
for hith in range(length):
switch1 = 0
if hith == 0 or hith == (length-1):
switch1 = 1
for width in range(length):
if width == 0 or width == (length - 1):
switch2 = 1
if switch1 or switch2:
print("*",end="")
else:
print(" ",end="")
switch2 = 0
print()
菱形:
length=int(input('>>>'))
for I in range(1,length+1):
for J in range(1,length+1):
if J <= (length - I):
print(" ",end="")
else:
print(" * ",end="")
for K in range(1,length+1):
if K < I:
print(" * ",end="")
else:
print(" ",end="")
print()
for I in range(length):
for J in range(length):
if J <= I:
print(" ",end="")
else:
print(" * ",end="")
for J in range(length):
if J+2 < (length-I):
print(" * ",end="")
else:
print(" ",end="")
print()
---------------------
打印菱形
length = int(input('>>>'))
for I in range(-length,length+1):
for J in range(-length,length+1):
if abs(I)+abs(J) <= length:
print('*',end='')
else:
print(' ',end='')
print()
--------------------
length = int(input('>>>'))
for I in range(-length,length+1):
print(" "*abs(I),end='')
print("*"*(length+1-abs(I))+"*"*(length-abs(I)))
*************************
#打印对角三角形
length = 5
for I in range(-length,length+1):
print(" "*(length-abs(I)),end='')
print("*"*abs(I)*2)
***********************
平行四边形:
length=int(input('>>>'))
for I in range(length):
for J in range(length):
if J < (length-I):
print(" ",end="")
else:
print(" * ",end="")
for K in range(length):
print(' * ',end='')
for J in range(length):
if J < (length-I):
print(" * ",end="")
else:
print(" ",end="")
print()
*********************************
中空平行四边形:
length=int(input('>>>'))
for I in range(length):
switch = 0
for J in range(length):
if J == (length-I-1) or I == (length-1):
print(" * ",end="")
else:
print(" ",end="")
switch = 0
for J in range(length):
if I == 0 or I == (length-1):
print(' * ',end='')
else:
print(' ',end='')
for J in range(length):
if J == (length-I-1) or I == 0:
print(" * ",end="")
else:
print(" ",end="")
print()
*****************************************
打印闪电:
length = int(input('>>>'))
str1=" "
str2="*"
for I in range(-length,length+1):
if I < 0:
print(str1*abs(I)+str2*(length-abs(I)+1))
elif I == 0:
print(str2*(length*2+1))
else:
print(str1*length+str2*(length-abs(I)+1))