-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCalculator.py
More file actions
69 lines (54 loc) · 1.13 KB
/
Calculator.py
File metadata and controls
69 lines (54 loc) · 1.13 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
Calculator module
"""
import abc
__author__ = 'Bruno'
class Context:
"""
Context'class
"""
def __init__(self, input_text):
"""
Constructor
"""
self.input_text = input_text
class Expression:
"""
Expression's class
"""
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def interpret(self, context):
"""
Interpret the Expression
"""
raise NotImplementedError
class NumberExpression(Expression):
"""
NumberExpression'class
"""
def __init__(self, number):
"""
Constructor
"""
self.number = number
def interpret(self, context):
"""
Interpret the Expression
"""
return self.number
class PlusExpression(Expression):
"""
PlusExpression's class
"""
def __init__(self, left, right):
"""
Constructor
"""
self.left = left
self.right = right
def interpret(self, context):
"""
Interpret the Expression
"""
return self.left.interpret(context) + self.right.interpret(context)