阶乘

方法1 2 3

def recur_fac(num,res=1):
    if num == 1:
        return res
    res = res * num
    return recur_fac(num - 1,res)

print(recur_fac(12))


from functools import reduce

print(reduce(lambda x , y :x * y,range(1,13)))

def factor(num):
    n = 1
    for i in range(2,num+1):
        n *= i
    return n

print(factor(5))

 

posted @ 2018-07-28 13:44  沧海一粒水  阅读(139)  评论(0编辑  收藏  举报