-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.py
More file actions
46 lines (39 loc) · 1 KB
/
Calculator.py
File metadata and controls
46 lines (39 loc) · 1 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
class Calculator:
def __init__(self, x, y):
self.x = x
self.y = y
def add(self):
return self.x + self.y
def sub(self):
return self.x - self.y
def devide(self):
return self.x / self.y
def multi(self):
return self.x * self.y
action = input("enter the quetion(between four main actions)\n(example: 2 * 3): ").replace(" ","")
run = 0
def Run():
global run
run = Calculator(float(num_x), float(num_y))
if "+" in action:
num_x = action.rpartition("+")[0]
num_y = action.rpartition("+")[2]
Run()
print(run.add())
elif "-" in action:
num_x = action.rpartition("-")[0]
num_y = action.rpartition("-")[2]
Run()
print(run.sub())
elif "/" in action:
num_x = action.rpartition("/")[0]
num_y = action.rpartition("/")[2]
Run()
print(run.devide())
elif "*" in action:
num_x = action.rpartition("*")[0]
num_y = action.rpartition("*")[2]
Run()
print(run.multi())
else:
print("cant reconized")