Advertisement
go6odn28

fibonacci_generator

Apr 20th, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.26 KB | None | 0 0
  1. def fibonacci():
  2.     start_number, next_number = 0, 1
  3.     while True:
  4.         yield start_number
  5.         start_number, next_number = next_number, start_number + next_number
  6.  
  7.  
  8. generator = fibonacci()
  9. for i in range(10):
  10.     print(next(generator), end=' ')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement