python 实现兔子生兔子示例
作者:liguo2016 时间:2022-04-13 05:15:11
如下所示:
# -*- coding: utf-8 -*-
# 简述:话说有一对可爱的兔子,出生后的第三个月开始,每一月都会生一对小兔子。
# 当小兔子长到第三个月后,也会每个月再生一对小小兔子。
# 问题:假设条件,兔子都不死的情况下,问每个月的兔子总数为多少?
def rabbit(month):
if month<=2:
return 2
else:
return rabbit(month-1)+rabbit(month-2)
if __name__=="__main__":
month=int(raw_input("请输入month:"))
for i in range(0,month):
print rabbit(i),
运行结果:
请输入month:20
2 2 2 4 6 10 16 26 42 68 110 178 288 466 754 1220 1974 3194 5168 8362
来源:https://blog.csdn.net/Guo_Apple/article/details/68940982
标签:python,兔子
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
编写数据库asp程序需注意的问题
2007-12-29 12:57:00
ASP初学者学习ASP指令
2008-10-14 17:27:00
Python数据可视化 pyecharts实现各种统计图表过程详解
2022-04-08 17:28:37
![](https://img.aspxhome.com/file/2023/4/82634_0s.png)
django.db.utils.ProgrammingError: (1146, u“Table‘’ doesn’t exist”)问题的解决
2022-01-12 14:02:31
![](https://img.aspxhome.com/file/2023/9/95599_0s.png)
如何由Sybase向SQL Server移植数据库
2009-01-20 15:56:00
利用Python脚本实现传递参数的三种方式分享
2023-07-11 03:45:44
![](https://img.aspxhome.com/file/2023/0/83710_0s.png)
asp实现的查询某关键词在MSSQL数据库位置的代码
2011-02-28 11:18:00
python中分组函数groupby和分组运算函数agg的使用
2023-05-25 03:15:48
基于Python+Tkinter实现一个简易计算器
2021-06-23 00:40:29
![](https://img.aspxhome.com/file/2023/4/72244_0s.png)
IIS出现Active Server Pages错误“ASP 0201”的修复工具
2009-05-25 18:06:00
理解python中装饰器的作用
2022-01-29 07:58:01
详解python websocket获取实时数据的几种常见链接方式
2023-09-20 08:22:23
利用Python写个简易版星空大战游戏
2023-08-26 14:07:42
![](https://img.aspxhome.com/file/2023/3/100813_0s.jpg)
如何提升JavaScript的运行速度(DOM篇)[译]
2009-02-25 12:24:00
Pygame实战之实现经典外星人游戏
2021-05-10 00:31:44
![](https://img.aspxhome.com/file/2023/3/90593_0s.gif)
形象化的reflow
2008-06-08 13:33:00
![](https://img.aspxhome.com/file/UploadPic/20086/8/ThumbnailServer2_51s.jpg)
Python编写百度贴吧的简单爬虫
2023-12-06 02:17:56
php截取字符串函数分享
2023-11-14 10:53:21
用Flash来作浏览历史功能
2009-08-11 14:47:00
![](https://img.aspxhome.com/file/UploadPic/20098/11/y200988221313-19s.gif)
python re.match函数的具体使用
2023-07-31 13:16:28
![](https://img.aspxhome.com/file/2023/7/60727_0s.png)