Discuss / Python / 作业

作业

Topic source

老阿_

#1 Created at ... [Delete] [Delete and Lock User]
def triangles(max):
    L, n = [1], 0
    while n < max:
        yield L
        i = 0
        n = n+1
        Ltemp=list(L)
        L.append(1)
        while i < n+1:
            #第一个1
            if i == 0:
                L[i] = 1
            #最后一个1
            elif i == n:
                L[i] = 1
            #其它元素,由上次L中元素计算得来
            else:
                L[i] = Ltemp[i-1]+Ltemp[i]
            i = i+1
    return 'done'

  • 1

Reply