Last active
August 2, 2022 12:43
-
-
Save TheOnlyWayUp/cf60a2ec96c9db9cb27f0ddb76dd2212 to your computer and use it in GitHub Desktop.
Basic OOP-Based Fibonacci Sequence 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 UserList: | |
def __init__(self, initlist: list = []): | |
self.data = initlist | |
class FiboList(UserList): | |
def __init__(self): | |
super().__init__([0, 1]) | |
def __next__(self): | |
sum_ = sum(self.data) | |
self.data.append(sum_) | |
self.data.pop(0) | |
return sum_ | |
def __iter__(self): | |
return self | |
# --- # | |
i = FiboList() | |
for number in i: | |
print(number) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Todos: