n = int(input('请输入层数:'))
for i in range(1, n + 1):
for j in range(1, i + 1):
print(f"{j}\t", end="")
for _ in range(n - i):
print("\t", end="")
print()
结果
模式B
代码
n = int(input('请输入层数:'))
for i in range(1, n + 1):
for j in range(1, n - i + 2):
print(f"{j}\t", end="")
for _ in range(i - 1):
print("\t", end="")
print()
结果
模式C
代码
n = int(input('请输入层数:'))
for i in range(1, n + 1):
for _ in range(n - i):
print("\t", end="")
for j in range(i, 0, -1):
print(f"{j}\t", end="")
print()
结果
模式D
代码
n = int(input('请输入层数:'))
for i in range(1, n + 1):
for _ in range(i - 1):
print("\t", end="")
for j in range(1, n - i + 2):
print(f"{j}\t", end="")
print()