starting with a factorial :
def function_factorial(n):
number=1
for i in range(1,n+1):
number *=i
return number
print(function_factorial( n)
use this application can acheved one number‘s factorial.
similar recurse function also can realized one number factorial:
def function_recurse(n):
if n==1:
return 1
return n*function_recurse(n-1)
print(function_recurse(n))
recurse function have follow characters:
1:in itself‘s function call itself realize it function performance
2:must setup a broke point ,otherwise it will enter a endless loop.
3: all recurse function can realize function loop also can do .
4:recurse productive low efficiency,workpiece ratio inefficiency
原文地址:https://www.cnblogs.com/alansuny/p/12495824.html
时间: 2024-11-07 20:44:36