Discuss / Python / 去度娘查了下通项公式23333

去度娘查了下通项公式23333

Topic source

Phioton

#1 Created at ... [Delete] [Delete and Lock User]

def factorial(s):

    i=1

    prod=1

    if s<=1:

        return 1

    else:

        while i <= s:

            prod=prod*i

            i=i+1

        return prod

def triangles():

    n=1

    while True:

        yield [factorial(n-1)//(factorial(m-1)*factorial(n-m))  for m in list(range(n+1))[1:]]

        n=n+1

    return 'done'

Phioton

#2 Created at ... [Delete] [Delete and Lock User]

不过这样好像没有“迭代”了,尴尬


  • 1

Reply