list = []
for x in range(1, 10):
list.append(x)
for x in range(1, 10):
for i in range(0, 10 - x):
print(" ", end = "")
for j in range(1, 2 * x):
while x > j:
print(list[x - j], end = "")
break
else:
print(list[j - x], end="")
print("")
----------------------------------------------------
运行结果
----------------------------------------------------
1
212
32123
4321234
543212345
65432123456
7654321234567
876543212345678
98765432123456789
Process finished with exit code 0