求阶乘,采用递归函数:
def factorial(n):
if n == 0 or n == 1:
return 1
else:
return (n * factorial(n -1))
print(factorial(2))
print(factorial(3))
print(factorial(10))
运行结果:
2
6
3628800
求阶乘,采用递归函数:
def factorial(n):
if n == 0 or n == 1:
return 1
else:
return (n * factorial(n -1))
print(factorial(2))
print(factorial(3))
print(factorial(10))
运行结果:
2
6
3628800