打卡 #生成器
Topic source#杨辉三角 方案1
def triangles(): L = [1] while True: yield L L.append(0) L = [L[i-1]+L[i] for i in range(len(L))]
#杨辉三角 方案2
def triangles(): L = [1] while True: yield L L.append(0) L = [1]+[L[i-1]+L[i] for i in range(1,len(L))]
#杨辉三角 方案3
def triangles(): L=[1] while True: yield L L = [1] + [L[i-1]+L[i] for i in range(1,len(L))] +[1]
有点没看懂,还有
##杨辉三角 方案1
def triangles(): L = [1] while True: yield L L.append(0) L = [L[i-1]+L[i] for i in range(len(L))]
##杨辉三角 方案2
def triangles(): L = [1] while True: yield L L.append(0) L = [1]+[L[i-1]+L[i] for i in range(1,len(L))]
##杨辉三角 方案3
def triangles(): L=[1] while True: yield L L = [1] + [L[i-1]+L[i] for i in range(1,len(L))] +[1]
这个方案一和二是有问题的,测试失败,用spyder输出看到了 0 list 2 [1, 0] 1 list 3 [1, 1, 0] 2 list 4 [1, 2, 1, 0] 3 list 5 [1, 3, 3, 1, 0] 4 list 6 [1, 4, 6, 4, 1, 0] 5 list 7 [1, 5, 10, 10, 5, 1, 0] 6 list 8 [1, 6, 15, 20, 15, 6, 1, 0] 7 list 9 [1, 7, 21, 35, 35, 21, 7, 1, 0] 8 list 10 [1, 8, 28, 56, 70, 56, 28, 8, 1, 0] 9 list 10 [1, 9, 36, 84, 126, 126, 84, 36, 9, 1]
- 1
JeromeYLuck
一段时间没来打卡了,加油加油!