# 重复打印5⾏星星
# j表示⾏号
j = 0
d = a = int(input("输入一个数字:"))
e=d
b = 0
while j <= d: # 底面边长为d=2*a+1
for i in range(1, a + 1, 1): # 每行先输出a个空格
print(' ', end='')
a = a - 1 # 递减1
# ⼀⾏星星的打印
i = 0 # 每次循环将i初始化为0
while i <= j: # 每行再输出j+1个*
print('*', end='')
i += 1
c = 0 # 每次循环将c初始化为0
while c < b: # 每行再输出b个*
print('*', end='')
c += 1
b = b + 1 # 递增1
print() # 换行
j += 1 # 递增1
m=1#输出菱形下半部分
n=2*e-1
while e>0:
for i in range(1, m+1, 1):
print(' ', end='')
m=m+1
for i in range(1, n + 1, 1):
print('*', end='')
n=n-2
print()
e=e-1
python打印菱形
最新推荐文章于 2024-03-23 10:19:45 发布