Discuss / Python / 作业

作业

Topic source

richardaaaa

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

def triangles(): L = [1] while True: yield L L = [1] + [x + L[i+1] for i,x in enumerate(L[:-1]) ] + [1]

筱枫_Edward

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

L=[1]                                                         
while True:
    yield L                                                           #打印出该list
    L=[L[x]+L[x+1] for x in range(len(L)-1)]        #计算下一行中间的值
    L.insert(0,1)                                                 #在开头插入1
    L.append(1)                                                 #在结尾添加1
    if len(L)>10:                                                 #仅输出10行

        break

  • 1

Reply