# 通過遞歸實現(xiàn)求n的階乘
def my_test(n):
if n is 0:
return 1
else:
return n*my_test(n-1)
print(my_test(5))
>> 120
# 通過普通循環(huán)實現(xiàn)求n的階乘
def my_test2(n):
result = n
for i in range(1,n):
result *= i
return result
print(my_test2(5))
>> 120