-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteger.py
62 lines (54 loc) · 2.22 KB
/
integer.py
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
# INTEGER CLASS, needs to be implemented
class integer:
def __init__(self, input):
if isinstance(input, str):
self.value = "("+input+")"
def __repr__(self):
return "integer(" + self.value + ")"
def __mul__(self,other):
inputnew = self.value + "*" + other.value
return integer(self, inputnew)
def __add__(self,other):
inputnew = self.value + "+" + other.value
return integer(self, inputnew)
def __sub__(self,other):
inputnew = self.value + "-" + other.value
return integer(self, inputnew)
def __truediv__(self,other):
inputnew = self.value + "/" + other.value
return integer(self, inputnew)
def __eq__(self, other):
self_string=self.value
other_string=other.value
if self_string==other_string:
return True
elif len(self_string)==len(other_string):
## multiplication and divison binds closer than addition/subtraction
if "+" in self_string and "+" in other_string:
a1 = self_string.split["+"][0]
b1 = self_string.split["+"][1]
b2 = other_string.split["+"][0]
a2 = other_string.split["+"][1]
return a1==a2 and b1==b2
elif "-" in self_string and "-" in other_string:
a1 = self_string.split["-"][0]
b1 = self_string.split["-"][1]
b2 = other_string.split["-"][0]
a2 = other_string.split["-"][1]
return a1==a2 and b1==b2
elif "*" in self_string and "*" in other_string:
a1 = self_string.split["*"][0]
b1 = self_string.split["*"][1]
b2 = other_string.split["*"][0]
a2 = other_string.split["*"][1]
return a1==a2 and b1==b2
elif "/" in self_string and "/" in other_string:
a1 = self_string.split["/"][0]
b1 = self_string.split["/"][1]
b2 = other_string.split["/"][0]
a2 = other_string.split["/"][1]
return a1==a2 and b1==b2
else:
return False
else:
return False