python下的杨辉三角

Python下的杨辉三角

#!/usr/bin/env python3
# -*- coding utf-8 -*-

def triangle():
    l = [1]
    a = 1
    while True:
        if a == 1:
            yield l
        else:
            l = [l[i-1] + l[i] for i in range(1,a-1)]
            l = [1] + l + [1]
            yield l
        a = a + 1

n = 0
for t in triangle():
    print(t)
    n = n + 1
    if n == 10:
        break
~                 
    原文作者:杨辉三角问题
    原文地址: https://blog.csdn.net/Lina_ACM/article/details/54232980
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞