coolplaylin 发表于 2023-1-11 22:46:00

杨辉三角生成器

开发的算法(

def PascalTriangle(limit:int) -> list:
    """
    limit
      限制生成的层数

    提示:如果你想无限生成杨辉三家的话,可使用下面这个
    """
    Result =
    for times in range(int(limit)):
      yield Result
      _Product =
      for i in range(0, len(Result)):
            if i + 1 > len(Result) - 1: #判断是否完成
                _Product.append(Result)
                break
            else:
                _Product.append(Result + Result)
      Result = _Product

def PascalTriangle_Loop() -> list:
    Result =
    while True:
      yield Result
      _Product =
      for i in range(0, len(Result)):
            if i + 1 > len(Result) - 1: #判断是否完成
                _Product.append(Result)
                break
            else:
                _Product.append(Result + Result)
      Result = _Product

sfqxx 发表于 2023-1-11 22:48:11

感谢分享

coolplaylin 发表于 2023-1-11 22:50:27

有错别字(6{:10_249:}

Mta123456 发表于 2023-1-12 08:30:09

感谢感谢!!

tomok 发表于 2023-1-12 09:57:10

谢谢分享

tiger20100907 发表于 2023-1-12 11:48:18

{:10_316:}感谢分享
页: [1]
查看完整版本: 杨辉三角生成器