0

Fibonacci series

14th Feb 2017, 11:00 AM
harshit
harshit - avatar
2 Antworten
+ 1
Fibonacci series is getting the next number by adding the 2 before it.. this is what I wrote for it. keeps it simple and easy to understand a=0 b=1 for i in range(7): print(a, end=' ') print(b, end=' ') a=b+a b=b+a
14th Feb 2017, 12:24 PM
LordHill
LordHill - avatar
- 1
from math import sqrt def F(n): return ((1+sqrt(5))**n-(1-sqrt(5))**n)/(2**n*sqrt(5)) very fast version but if you follow deffiniton: def SubFib(startNumber, endNumber): for cur in F(): if cur > endNumber: return if cur >= startNumber: yield cur for i in SubFib(10, 200): print i
14th Feb 2017, 11:09 AM
Roman Santa
Roman Santa - avatar