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

Function fibonacci_generator

project_euler/problem_025/sol2.py:30–49  ·  view source on GitHub ↗

A generator that produces numbers in the Fibonacci sequence >>> generator = fibonacci_generator() >>> next(generator) 1 >>> next(generator) 2 >>> next(generator) 3 >>> next(generator) 5 >>> next(generator) 8

()

Source from the content-addressed store, hash-verified

28
29
30def fibonacci_generator() -> Generator[int]:
31 """
32 A generator that produces numbers in the Fibonacci sequence
33
34 >>> generator = fibonacci_generator()
35 >>> next(generator)
36 1
37 >>> next(generator)
38 2
39 >>> next(generator)
40 3
41 >>> next(generator)
42 5
43 >>> next(generator)
44 8
45 """
46 a, b = 0, 1
47 while True:
48 a, b = b, a + b
49 yield b
50
51
52def solution(n: int = 1000) -> int:

Callers 1

solutionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected