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

Posted qmzp

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[转载] 打印三角形数据输出相关的知识,希望对你有一定的参考价值。

 

输出结果:

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

 

以上是关于[转载] 打印三角形数据输出的主要内容,如果未能解决你的问题,请参考以下文章

用java打印菱形。

用js写输出星号直角三角形的代码

c++输出三角形

怎样用Java代码打印并输出如下图形

python打印杨辉三角的两种方法及详解

java怎么用一个一维数组输出杨辉三角(补充完整下列代码)