利用生成器输出杨辉三角

def tri():
    l = [1]
    while True:
        yield l
        new_l = [l[i] + l[i+1] for i in range(len(l) -1)]
        l = new_l
        l.insert(0,1)
        l.append(1)

n = int(input())
for i in tri():
    n -= 1
    if n < 0:
        break
    print(i)
上一篇:Mysql触发器


下一篇:python中3D图像的绘制