1.正三角形
a=int(input('\n'))
for i in range(1,a+1):
s=a-i
for j in range(0,s):
print(" ",end="")
for k in range(i*2-1):
print('*',end="")
print()
设计思路:
a=int(input('\n'))
for s in range(a,0,-1):
for k in range(0,a-s):
print(" ",end='')
for c in range(s*2-1):
print("*",end="")
print()
3.菱形
a=int(input('\n'))
for i in range(1,a+1):
s=a-i
for j in range(0,s):
print(" ",end="")
for k in range(i*2-1):
print('*',end="")
print()
for s in range(i-1,0,-1):
for k in range(0,a-s):
print(" ",end='')
for c in range(s*2-1):
print("*",end="")
print()
设计思路
a=int(input('\n'))
for i in range(1,a+1):
s=a-i
for j in range(0,s):
print(" ",end="")
for k in range(i*2-1):
if k==0 or k==i*2-2:
print('*',end="")
else:
print(' ',end="")
print()
for s in range(i-1,0,-1):
for k in range(0,a-s):
print(" ",end='')
for c in range(s*2-1):
if c==0 or c==s*2-2:
print('*',end="")
else:
print(' ',end="")
print()