Professional Documents
Culture Documents
# trib(0) = 0
# trib(1) = 0
# trib(2) = 1
class InputReader(ABC):
"""
The abstract class of a number input reader which could be
inherited by other classes.
"""
@abstractmethod
def get_input(self) -> int:
"""
Method which reads some kind of input.
This method should returns an integer
"""
pass
class StdInputReader:
"""
This class inherits InputReader.
and makes reading an integer from the standard input.
class TextFileInputReader:
"""
This class inherits InputReader
and makes reading an integer from a text file.
"""
class Calculator:
"""
One method named: tribonacci
- one parameter: n
- one returned value: tribonacci of n using the recursive process
"""
def trib(self,n):
if n == 0:
return 0
if n == 1:
return 0
elif n== 2:
return 1
else:
return self.trib(n-3) + self.trib(n-2) + self.trib(n-3)
###################################################################################
###########
class CalculatorBis:
"""
One method named: tribonacci
- one parameter: n
- one returned value: tribonacci of n using the iterative process
"""
def tribonacci(n):
a,b,c=0,0,1
for _ in range(n):
trib = a + b + c
a=b
b=c
c=trib
return a
print(tribonacci(12))
class CalculatorApp:
"""
2 attributes:
- a reader of type StdInputReader, or TextFileInputReader
- a calculator of type CalculatorIterative or CalculatorRecursive
def main():
app1 = CalculatorApp(StdInputReader(), Calculator())
app2 = CalculatorApp(TextFileInputReader("./input.txt"), CalculatorBis())
if choice == 1:
print(app1.calculate())
elif choice == 2:
print(app2.calculate())
else:
sys.exit("Bye")
if __name__ == "__main__":
main()