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()

  

 

posted @ 2019-10-04 12:41  从前有座山,山上  阅读(229)  评论(0编辑  收藏  举报