20150516 打印N阶杨辉三角形

使用python打印N阶杨辉三角形

代碼如下:
import numpy as np

def SpecicalData(N):
    if(N<0):
        return 
    else:
        L1 = [1] #The fist line
        print(L1)
        for i in range(2, N):
            L = [1, 1]                     
            for j in range(i-2):
                L.insert(j+1, L1[j] + L1[j+1])
            print(L)
            L1 = L
        
    

 + L1[j+1])\n            print(L)\n            L1 = L\n        \n    ","execution_count":16,"outputs":[]}

測試代碼以及輸出如下:

SpecicalData(9)
[1]
[1, 1]
[1, 2, 1]
[1, 3, 3, 1]
[1, 4, 6, 4, 1]
[1, 5, 10, 10, 5, 1]
[1, 6, 15, 20, 15, 6, 1]
[1, 7, 21, 35, 35, 21, 7, 1]

阅读更多
下一篇20180517函數用於計算矩陣相乘
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭