标签:
输出结果:
this is [1]
this is [1, 1]
this is [1, 2, 1]
this is [1, 3, 3, 1]
this is [1, 4, 6, 4, 1]
this is [1, 5, 10, 10, 5, 1]
this is [1, 6, 15, 20, 15, 6, 1]
this is [1, 7, 21, 35, 35, 21, 7, 1]
this is [1, 8, 28, 56, 70, 56, 28, 8, 1]
this is [1, 9, 36, 84, 126, 126, 84, 36, 9, 1]
def triangles(): L = [1] while True: yield L L1 = L[:] L = [] i = 0 while i < len(L1) - 1: L.append(L1[i] + L1[i+1]) i = i + 1 L.insert(0, 1) L.append(1) if __name__ == "__main__": n = 0 for t in triangles(): print(" this is %s" %t) n = n + 1 if n == 10: break
标签:
原文地址:http://www.cnblogs.com/lifeinsmile/p/5272564.html