Created
December 29, 2023 13:19
-
-
Save ozscosta/fde6575f103f69cb70dc73791065efab to your computer and use it in GitHub Desktop.
Fibbonaci in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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