Discuss / Python / 出错了求解答

### 出错了求解答

Topic source

#### 世事逝时

#1 Created at ... [Delete] [Delete and Lock User]
    tuple = [1]
yield tuple
tuple.append(1)
yield tuple
while True:
n = len(tuple)
while n>1:
tuple[n-1] = tuple[n-1]+tuple[n-2]
n = n - 1
tuple.append(1)
yield tuple



[[1, 9, 36, 84, 126, 126, 84, 36, 9, 1],

[1, 9, 36, 84, 126, 126, 84, 36, 9, 1],

[1, 9, 36, 84, 126, 126, 84, 36, 9, 1],

[1, 9, 36, 84, 126, 126, 84, 36, 9, 1],

[1, 9, 36, 84, 126, 126, 84, 36, 9, 1],

[1, 9, 36, 84, 126, 126, 84, 36, 9, 1],

[1, 9, 36, 84, 126, 126, 84, 36, 9, 1],

[1, 9, 36, 84, 126, 126, 84, 36, 9, 1],

[1, 9, 36, 84, 126, 126, 84, 36, 9, 1],

[1, 9, 36, 84, 126, 126, 84, 36, 9, 1]]

#### 杰成张

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

def triangles():    tuple = [1]    yield tuple    tuple = [1,1]    yield tuple    while True:        n = len(tuple)        while n > 1:            tuple = tuple+[]            tuple[n - 1] = tuple[n - 1] + tuple[n - 2]            n = n - 1        tuple = tuple+[1]        yield tuple


• 1