Python打印杨辉三角

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

 

    原文作者:杨辉三角问题
    原文地址: https://blog.csdn.net/YiHong_Li/article/details/81120774
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞