【操作】 使用递归函数计算阶乘(factorial)
def factorial(n):
if n == 1:
return 1
return n * factorial(n - 1)
for i in range(1, 6):
print(i, '!=', factorial(i))
输出结果:
D:\work\python\two\venv\Scripts\python.exe D:\work\python\two\mypy18.py
1 != 1
2 != 2
3 != 6
4 != 24
5 != 120
标签:递归函数,python,two,82,factorial,阶乘
From: https://www.cnblogs.com/yuanzijian/p/16906043.html