1. 程式人生 > >輸出楊輝三角的前m行,生成器的應用

輸出楊輝三角的前m行,生成器的應用

m = int(input('請輸入行數:'))
def triangles():
    L = [1]
    while len(L) < = m:
        yield L
        L.append(0)
        L = [L[i - 1] + L[i] for i in range(len(L))]
for t in triangles():
    print(t)