码迷,mamicode.com
首页 > 其他好文 > 详细

[转载] 打印三角形数据输出

时间:2016-03-13 19:49:13      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

 

输出结果:

this is [1]
this is [1, 1]
this is [1, 2, 1]
this is [1, 3, 3, 1]
this is [1, 4, 6, 4, 1]
this is [1, 5, 10, 10, 5, 1]
this is [1, 6, 15, 20, 15, 6, 1]
this is [1, 7, 21, 35, 35, 21, 7, 1]
this is [1, 8, 28, 56, 70, 56, 28, 8, 1]
this is [1, 9, 36, 84, 126, 126, 84, 36, 9, 1]

def triangles():
    L = [1]
    while True:
        yield L
        L1 = L[:]
        L = []
        i = 0
        while i < len(L1) - 1:
            L.append(L1[i] + L1[i+1])
            i = i + 1
        L.insert(0, 1)
        L.append(1)
        
if __name__ == "__main__": 
    n = 0
    for t in triangles():
        print(" this is %s" %t)
        n = n + 1
        if n == 10:
            break

 

[转载] 打印三角形数据输出

标签:

原文地址:http://www.cnblogs.com/lifeinsmile/p/5272564.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!