Last active
August 29, 2015 14:03
-
-
Save rohit-jamuar/ed69663123665aed272f to your computer and use it in GitHub Desktop.
Fibonacci sequence generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fibo_num_generator(): | |
''' | |
Create an instance of 'fibo_num_generator' to use it as a generator - | |
e.g. g = fibo_num_generator() | |
In order to get the next element in the sequence --> g.next() | |
''' | |
yield 0 | |
yield 1 | |
yield 1 | |
a, b = 1, 1 | |
while True: | |
a, b = b, a+b | |
yield b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment