[Python急救站]打印菱形
打印菱形程序
row = int(input("请输入要打印的列数: "))
#打印上面三角
for i in range(row): # i控制行数
for j in range(row - 1 - i): # 空格数和行数的关系
print(" ", end="")
for k in range(2 * i + 1): # *号奇数递增
print("*", end="")
print("\n")
# 打印下面三角
for i in range(row - 1): # 行数减一
for j in range(i + 1):
print(" ", end="")
for k in range(2 * (row - 1 - i) - 1): # *奇数递减
print("*", end="")
print("\n")
程序运行如下: