Discuss / Python / python实现杨辉三角

python实现杨辉三角

Topic source

Raighne_Weng

#1 Created at ... [Delete] [Delete and Lock User]
def triangle(n):
    L=[1]
    while True:
        yield(L)
        L.append(0)
        L=[L[i]+L[i-1] for i in range(len(L))]
        if len(L)>10:
            break
    return "done"

g=triangle(10)
for i in g:
    print(i)

_神不在

#2 Created at ... [Delete] [Delete and Lock User]

可以,学习了

这个比较牛

方法比较讨巧

tanti_conan

#4 Created at ... [Delete] [Delete and Lock User]

添加一个0,省了很多代码,非常聪明的办法

请问每一行是怎么实现排序的啊 比如第三行 [l[0],[l[1]+l[0],[l[2]+l[1]] 不应该是[1,1,2]吗 ?我是新手 求教啊


  • 1

Reply