阶乘
#递归计算阶乘 def factorial(n): if n == 1: return 1 return n*factorial(n-1) result = factorial(6) print('阶乘:',result)
累加
#递归求和 def accumulation(n): if n == 0: return 0 return n+accumulation(n-1) print('累加:',accumulation(6))
斐波那契数列
#斐波那契数列 def fibonacci(n): if n == 0: return 0 if n == 1: return 1 return fibonacci(n-1)+fibonacci(n-2) print('斐波那契数列:',fibonacci(9))