Discuss / Python / 杨辉三角 求教那边不对

杨辉三角 求教那边不对

Topic source

奕先森Jr

#1 Created at ... [Delete] [Delete and Lock User]

def triangles(max): L=[1],n=0 while n<max: yield L L=[1]+[L[i]+L[i+1] for i in range(len(L)-1)]+[1] n=n+1

for t in triangles(10): print(t)

陈Li斌

#2 Created at ... [Delete] [Delete and Lock User]

请问L[0]+L[1]是什么意思啊

改了下这个,可以正常输出, L=[1] n=0

l[0]+l[1]就是列表的这两个元素之和,1+1=2


  • 1

Reply