def triangles(num):
L2 = [1, 1]
if num >= 1:
L1=1
yield L1
if num >= 2:
L = [1, 1]
yield L
if num >= 3:
for i in range(num-2):
L3 = [L2[i]+L2[i+1] for i in range(len(L2)-1)]
L3.insert(0,1)
L3.append(1)
L2 = L3
yield L3
for n in triangles(10):
print(n)
原文:https://www.cnblogs.com/LewisAAA/p/9502614.html