Skip to content

Commit

Permalink
Generating fibonacci numbers using generator method
Browse files Browse the repository at this point in the history
  • Loading branch information
samarth1402 committed Jan 29, 2018
1 parent 57064df commit 513d16a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions week_5/in-text/video_ques/fib_generator_eg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def fibGen():
fibn_1 = 1 # (n-1) term
fibn_2 = 0 # (n-2) term
while True:
next = fibn_1 + fibn_2
yield next
fibn_2 = fibn_1
fibn_1 = next

f = fibGen()
for i in range (5):
print(f.__next__())




0 comments on commit 513d16a

Please sign in to comment.