|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
递归是函数调用自身的一种行为,有正确的返回条件
Python3 默认递归的设置是100*
Import sys
Sys.setrecrsionlimit() 用来设置递归的深度
Factorial通过阶乘初步了解递归
函数法:
def factorial(n):
result = n
for i in range(1,n):
result = result * i
return result
temp = int(input('import a number:'))
result = factorial(temp)
print('%d 的阶乘是:%d!'% (temp,result))
递归法
def factorial(n):
if n == 1:
return 1
else:
return n * factorial(n-1)
temp = int(input('import a number:'))
result = factorial(temp)
print('%d 的阶乘是:%d!'% (temp,result))
|
|