Python – 使用 for 循环用“ * ”打印等腰三角形
layer = int(input("请输入要打印的层数:"))
for x in range(1, layer + 1):
space_num = layer - x
for y in range(1, space_num + 1):
print(" ", end="")
star_num = 2 * x - 1
for y in range(1, star_num + 1):
print("*", end="")
print("")
输出举例: