MCPcopy Create free account
hub / github.com/geekcomputers/Python / fibonacci_generator

Function fibonacci_generator

FibonacciNumbersWithGenerators.py:1–15  ·  view source on GitHub ↗

Generating function up to n fibonacci numbers iteratively Params: n: int Return: int

(n=None)

Source from the content-addressed store, hash-verified

1def 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
18for n_fibo in fibonacci_generator(7):

Calls

no outgoing calls

Tested by

no test coverage detected