python实现斐波那契数列
2018-04-11 16:57
375 查看
''' 斐波那契数列指的是这样一个数列 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368........ 这个数列从第3项开始,每一项都等于前两项之和。 ''' month1 = int(input('输入月数:')) month2 = month1 # 第一种方法 a , b = 0 , 1 while month1 != 0: print(b, end=',') a , b = b , a+b month1 -= 1 # 第二种方法 def fbnqQueue(month_temp): num_list = [] for i in range(month_temp): if i == 0 or i == 1: num_list.append(1) else: num_list.append(num_list[i-1] + num_list[i-2]) return num_list fbnq_queue = fbnqQueue(month2) print() print(fbnq_queue)运行结果:输入月数:10
1,1,2,3,5,8,13,21,34,55,
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
相关文章推荐
- python用迭代器的方式实现斐波那契数列
- 分别用的列表,递归,生成器三种方式创建出n个元素的斐波那契数列(Python3实现)
- 斐波那契数列(C++ 和 Python 实现)
- 用Python简单实现斐波那契数列
- 详解python使用递归、尾递归、循环三种方式实现斐波那契数列
- 斐波那契数列的算法实现 —— python
- Python 实现斐波那契数列 (黄金分割数列)
- 斐波那契数列的实现(Python)
- python超简单实现斐波那契数列
- Python 几行实现斐波那契数列
- python实现最简单斐波那契数列
- python3 迭代器实现斐波那契数列
- python学习系列---斐波那契数列的多种实现
- 斐波那契数列(Fibonacci sequence)Python实现的三种方案:列表 递归 生成器
- python学习系列---斐波那契数列的多种实现
- python实现1、使用迭代器实现斐波那契数列;2、从迭代器得到序列
- 斐波那契数列 python实现
- python实现的斐波那契数列
- Python3基础 用 函数递归实现 斐波那契数列
- python语言实现斐波那契数列