Discuss / Python / test

东东男装

#1 Created at ... [Delete] [Delete and Lock User]
# -*- coding: utf-8 -*-
def triangles():
    L = [1]
    a,b = 0,0
    while True:
        yield L
        L = [1] + [L[i] + L[i+1] for i in range(b)] + [1]
        b = b + 1

n = 0
for t in triangles():
    print(t)
    n = n + 1
    if n == 10:
        break

Henry_Smith

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

这里定义a,b = 0,0 ,a起什么作用? 下文沒有出现对a的调用。

-- coding: utf-8 --

def triangles(): L = [1] a,b = 0,0 while True: yield L L = [1] + [L[i] + L[i+1] for i in range(b)] + [1] b = b + 1


  • 1

Reply