算法(递归)

1:阶乘

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

def power(x, n):
    if n == 0:
        return 1
    else:
        return x * power(x, n-1)
3:斐波那契数列

def Fibonacci(num):
    if num <= 1:
        return 1
    else:
        return Fibonacci(num -1) + Fibonacci(num - 2)

你可能感兴趣的:(算法(递归))