杨辉三角--生成器版
# 杨辉三角 def triangle(): li = [1] while True: yield li lis = [] lis.extend([li[0]]) for j in range(len(li)-1): lis.append((li[j]+li[j+1])) else: lis.extend([li[0]]) li = lis tri_list = triangle() for i in range(10): print(next(tri_list))
# 杨辉三角 def triangle(): li = [1] while True: yield li lis = [] lis.extend([li[0]]) for j in range(len(li)-1): lis.append((li[j]+li[j+1])) else: lis.extend([li[0]]) li = lis tri_list = triangle() for i in range(10): print(next(tri_list))