# Python 函数递归(1) 使用函数递归的方式可以方便的写出阶乘计算。 ```python # -*- coding: UTF-8 -*- # TODO(You): 请实现递归计算阶乘 if __name__ == '__main__': print(fact(998)) ``` 请选出下面的 Python 递归阶乘实现代码中,错误 的选项。 ## template ```python def fact(n): if n == 1: return 1 return n*fact(n-1) if __name__ == '__main__': print(fact(998)) ``` ## 答案 ```python def inner_fact(n, m, r): if m == n: return r return inner_fact(n, m+1, r*m) def fact4(n): return inner_fact(n, 1, 1) ``` ## 选项 ### A ```python def fact(n): if n == 1: return 1 return n*fact(n-1) ``` ### B ```python def inner_fact(n, r): if n == 1: return r return inner_fact(n-1, r*n) def fact(n): return inner_fact(n, 1) ``` ### C ```python def inner_fact(n, m): if m == n: return n return m*inner_fact(n, m+1) def fact(n): return inner_fact(n,1) ```