Python--递归 斐那锲波,,迭代实现def fa
Python--递归 斐那锲波,,迭代实现def fa
迭代实现
def fab(n): n1 = 1 n2 = 1 n3 = 1 if n < 1: print(‘输入有误!‘) return -1 while (n - 2) > 0: n3 = n2 + n1 n1 = n2 n2 = n3 n -= 1 return n3daylop = int(input(‘请输入月数:‘))result = fab(daylop)if result != -1: print(‘总共有%d对小兔子诞生!‘ % result)
递归
def fab(n): if n < 1: print(‘输入有误!‘) return -1 if n == 1 or n ==2: return 1 else: return fab(n-1) + fab(n-2)dalop = int(input(‘请输入月数:‘))result = fab(dalop)if result !=-1: print(‘总共或有%d对兔子‘% result)
Python--递归 斐那锲波
相关内容
- Python输出特殊字符图形(一)大雁南飞,, 1 #condin
- Python——交互式图形编程,,1、图形显示图素法像
- python计算工资个税,, 1 # -*- c
- Python之函数练习题,,一、简述普通参数、指
- python学习之工资结算,,import os,
- 冒泡排序(bubble_sort)——Python实现,,#冒泡排序#作用
- Python用subprocess的Popen来调用系统命令,,当我们须要调用
- Ubuntu下python的BeautifulSoup和rsa安装方法,,最近因为《信
- Python3之harbor sdk api,,环境python3源
- python中requests库get方法带参数请求,,起因是想爬五等分
评论关闭