# 通过递归实现求n的阶乘
def my_test(n):
if n is 0:
return 1
else:
return n*my_test(n-1)
print(my_test(5))
>> 120
# 通过普通循环实现求n的阶乘
def my_test2(n):
result = n
for i in range(1,n):
result *= i
return result
print(my_test2(5))
>> 120
原文地址:http://blog.51cto.com/10412806/2285586
时间: 2024-10-01 05:05:18