刚刚学习了 斐波那契数列,整理一下思路,写个博文给未来的学弟学妹参考一下,希望能够帮助到他们 永远爱你们的 ----新宝宝 经历过简单的学习之后,写出一个比较简单的代码,斐波那契数列:具体程序如下: 1: # Fibonacci series: 斐波纳契数列 # 两个元素的总和确定了下一个数 a, b = 0, 1 while b < 10: print(b) a, b = b, a+b 执行上面的代码会得到: 这个例子介绍了几个新特征. 第一行包含了一个复合赋值:变量 a 和 b 同时得到新值…
本题来自 Project Euler 第2题:https://projecteuler.net/problem=2 # Each new term in the Fibonacci sequence is generated # by adding the previous two terms. # By starting with 1 and 2, the first 10 terms will be: # 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... # By…
day16 --------------------------------------------------------------- 实例024:斐波那契数列II 题目 有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13-求出这个数列的前20项之和. 分析:就是斐波那契数列的后一项除以前一项,于是写了两个函数 1 def fbs(num): 2 a = [0,1] 3 if num<=2: 4 return a 5 else: 6 for i in range(1,int(…
day4 --------------------------------------------------------------- 实例006:斐波那契数列 题目 斐波那契数列. 题目没说清楚,大概说的是输出制定长度的数列吧,想了想实现如下: 1 a = int(input("请输入斐波那契数列位数:")) 2 list = [] 3 for i in range(a): 4 if i <2: 5 list.append(i) 6 else: 7 list.append(l…