-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
37 lines (27 loc) · 933 Bytes
/
main.py
File metadata and controls
37 lines (27 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from collections import abc
__author__ = "Parham Alvani"
class Fibonacci(abc.Container):
"""
A class for making fibonacci number with divide & conquer and
dynamic programming methods.
"""
def __init__(self):
self.list: list[int] = [0, 1]
def __contains__(self, fn: int) -> bool:
while fn > self.list[-1]:
self.list.append(self.list[-1] + self.list[-2])
return fn in self.list
def __getitem__(self, index: int) -> int:
"""
returns fibonacci squence at the given index.
if it does not have the given index, it will calculate it.
"""
while len(self.list) - 1 < index:
self.list.append(self.list[-1] + self.list[-2])
return self.list[index]
fibonacci = Fibonacci()
var = input("Please enter fibonacci sequence number ")
var = int(var)
print(fibonacci[var])
print(var in fibonacci)
print(fibonacci.list)