Advertisement
pacho_the_python

fib_generator

Apr 22nd, 2024
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. def fibonacci(n):
  2.     """
  3.    Fibonacci Generator Function
  4.    """
  5.     a, b = 0, 1
  6.     count = 0
  7.     while count < n:
  8.         yield a
  9.         a, b = b, a + b
  10.         count += 1
  11.  
  12.  
  13. def fibonacci_output(generator):
  14.     result = [fib for fib in generator]
  15.     return f"{', '.join(map(str, result))}"
  16.  
  17. print(fibonacci_output(fibonacci(10)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement