Skip to content

Commit 500a021

Browse files
Merge pull request #1679 from LuisZapataYamo/patch-1
Example of generators
2 parents 306e1c4 + 32a986a commit 500a021

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

FibonacciNumbersWithGenerators.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def fibonacci_generator(n = None):
2+
"""
3+
Generating function up to n fibonacci numbers iteratively
4+
Params:
5+
n: int
6+
Return:
7+
int
8+
"""
9+
f0, f1 = 0, 1
10+
yield f1
11+
while n == None or n > 1:
12+
fn = f0 + f1
13+
yield fn
14+
f0, f1 = f1, fn
15+
n -= 1
16+
17+
for n_fibo in fibonacci(7):
18+
print(n_fibo)

0 commit comments

Comments
 (0)