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()``````

1. 确定输入行数
2. 判断第一个字符距离左边界多少个空格
3. 判断星号（）与行数之间的对应关系（行数2-1）
4. 每一行输出之后需要换行
2.倒三角
``````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()``````

1. 菱形的本质可以看做两个三角形拼接而成（一个正三角与一个倒三角）
2. 需要注意的是输出倒三角的时候应该把第一行去掉（i-1）不然回出现多一行的情况
3. 倒三角的空格控制可以借助输入的行数来减去第一个循环
4打印镂空的菱形
``````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()``````