python 杨辉三角

Posted jiaxinwei

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 杨辉三角相关的知识,希望对你有一定的参考价值。

# 杨辉三角
x  = [[1]*i for i in range(1,11)] #数组生成方式
print(x)

for i in range(2,10):
    for j in range(1,i):
        x[i][j] = x[i-1][j-1] + x[i-1][j]

for i in range(0,10):
    for j in range(10-i):
        print(" ",end=" ")
    for j in range(0,i+1):
        print("%3d"%x[i][j],end=‘ ‘)
    print()

  技术图片

 

以上是关于python 杨辉三角的主要内容,如果未能解决你的问题,请参考以下文章

python 杨辉三角

python杨辉三角形原理

Python实现杨辉三角

python打印杨辉三角

python 实现杨辉三角(依旧遗留问题)

Python 中使用 forwhile 循环打印杨辉三角练习(列表索引练习)。