标签:bsp int yield end 杨辉三角 返回 div 执行 循环
1 ‘‘‘ 2 1 3 1, 1 4 1, 2, 1 5 1, 3, 3, 1 6 1, 4, 6, 4, 1 7 ‘‘‘ 8 # def YangHui (num = 10): 9 # LL = [[1]] 10 # print([1]) 11 # for i in range(1,num): 12 # # LL.append([(0 if j== 0 else LL[i-1][j-1])+ (0 if j ==len(LL[i-1]) else LL[i-1][j]) for j in range(i+1)]) 13 # print([(0 if j== 0 else LL[i-1][j-1])+ (0 if j ==len(LL[i-1]) else LL[i-1][j]) for j in range(i+1)]) 14 # 15 # print(YangHui (num = 10)) 16 17 def fun(n): 18 N = [1] 19 t = 0 20 while t < n: 21 yield N 22 t = t + 1 23 N.append(0) 24 N = [N[i-1] + N[i] for i in range(len(N))] 25 26 for i in fun(6): 27 print(i) 28 #在每次调用next()的时候执行,遇到yield语句返回,再次执行时从上次返回的yield语句处继续执行。
# 循环加每一项 如: 1,2,1,0 1+0,1+2,2+1,0+1
标签:bsp int yield end 杨辉三角 返回 div 执行 循环
原文地址:https://www.cnblogs.com/JerryZao/p/8798580.html