python 要点10:递归 recursion
2018-03-02 20:05
211 查看
通过自我的循环,产生递归。# 递归 recursion
def f4(a1,a2): # 斐波那契数列
if a1 > 10000:
return
print(a1)
a3 = a1 + a2
f4(a2,a3)
f4(0,1)
############ 循环5次输出150 ####################
def f5(i):
if i == 5:
return 150
r = f5(i+1)
return r
ren = f5(1)
print(ren)
######### 找到第10个斐波那契数列的值 #######################
def f4(depth,a1,a2):
if depth == 10:
return a1
a3 = a1 + a2
r = f4(depth + 1,a2,a3)
return r
ren = f4(1,0,1)
print(ren)
def f4(a1,a2): # 斐波那契数列
if a1 > 10000:
return
print(a1)
a3 = a1 + a2
f4(a2,a3)
f4(0,1)
############ 循环5次输出150 ####################
def f5(i):
if i == 5:
return 150
r = f5(i+1)
return r
ren = f5(1)
print(ren)
######### 找到第10个斐波那契数列的值 #######################
def f4(depth,a1,a2):
if depth == 10:
return a1
a3 = a1 + a2
r = f4(depth + 1,a2,a3)
return r
ren = f4(1,0,1)
print(ren)
相关文章推荐
- 10 种机器学习算法的要点(附 Python 和 R 代码)
- 10 种机器学习算法的要点(附 Python 和 R 代码)
- 10 种机器学习算法的要点(附 Python 和 R 代码)
- 10 种机器学习算法的要点(附 Python 和 R 代码)
- 10 种机器学习算法的要点(附 Python 和 R 代码)
- 10_种机器学习算法的要点(附_Python_和_R_代码)
- 当python超出默认递归次数RecursionError: maximum recursion depth exceeded in comparison
- Python递归(recursion)专题
- Python的最大递归深度错误 “maximum recursion depth exceeded while calling a Python object”
- python递归深度报错--RuntimeError: maximum recursion depth exceeded
- 10 种机器学习算法的要点(附 Python 和 R 代码)
- python 最大递归次数 RuntimeError: maximum recursion depth exceeded
- 10 种机器学习算法的要点(附 Python 和 R 代码)
- python递归报错 RuntimeError: maximum recursion depth exceeded
- python 递归实例(recursion in real world using python)
- 10 种机器学习算法的要点(附 Python)(转载)
- 10 种机器学习算法的要点(附 Python 和 R 代码)
- python递归深度报错--RuntimeError: maximum recursion depth exceeded
- Python RuntimeError: maximum recursion depth exceeded in cmp 超过最大递归深度错误
- 10 种机器学习算法的要点(附 Python 和 R 代码)