Discuss / Python / 练习

练习

Topic source
# -*- coding: utf-8 -*-

def triangles():
    result = [1]
    while True:
        yield result
        result.append(0)
        result = [result[i]+result[i-1] for i in range(len(result))]


if __name__ == '__main__':
    triangle_generator = triangles()
    for i in range(10):
        print(next(triangle_generator))

  • 1

Reply