Discuss / Python / 杨辉三角

杨辉三角

Topic source

感谢评论区的旁友们!

def triangles(max):
    L=[1]
    yield L
    n=1
    while n<max:
        L=[1]+[L[n]+L[n+1] for n in range(len(L)-1)]+[1]
        yield L
        n=n+1

#结果测试:
for m in triangles(10):
    print(m)

  • 1

Reply