輸出楊輝三角的前m行,生成器的應用
阿新 • • 發佈:2019-02-11
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)