python 实现函数的递归

kk=5
def factorial(n):

    result = 1
    for i in range(2, n+1):
        result *= i
    return result

print(factorial(kk))

def factorial(n):
     if n == 1:
         return 1
     else:
         return n * factorial(n - 1)

print(factorial(kk))
120
120
posted @ 2018-06-23 21:44  luoganttcc  阅读(88)  评论(0编辑  收藏  举报