Skip to content

Instantly share code, notes, and snippets.

@ozscosta
Created December 29, 2023 13:19
Show Gist options
  • Save ozscosta/fde6575f103f69cb70dc73791065efab to your computer and use it in GitHub Desktop.
Save ozscosta/fde6575f103f69cb70dc73791065efab to your computer and use it in GitHub Desktop.
Fibbonaci in python
class Fibonacci:
def __init__(self, first: int = 1):
self.curr = 1
self.last = 0
while self.value < first:
self.__next__()
@property
def value(self) -> int:
return self.curr + self.last
def __next__(self):
self.last, self.curr = self.curr, self.value
return self.curr
if __name__ == '__main__':
fibo = Fibonacci(19)
for _ in range(5):
print(next(fibo))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment