-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator2.py
More file actions
51 lines (26 loc) · 866 Bytes
/
Copy pathcalculator2.py
File metadata and controls
51 lines (26 loc) · 866 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
38
39
40
41
42
"""creating a calculator class"""
from calculator import substract,add,multi,div
class calculator:
def __init__(self,n1,n2):
self.n1 = n1
self.n2 = n2
def operation(self,op):
if op=="+":
print(f"addition:{add(int(self.n1),int(self.n2))}")
elif op=="-":
print(f"substraction:{substract(int(self.n1),int(self.n2))}")
elif op=="*":
print(f"multiply:{multi(int(self.n1),int(self.n2))}")
elif op=="/":
print(f"divide:{div(int(self.n1),int(self.n2))}")
def add(self):
return self.n1+self.n2
def substract(self):
return self.n1-self.n2
def multi(self):
return self.n1*self.n2
def div(self):
return self.n1/self.n2
if __name__=='__main__':
solution=calculator(8,9)
solution.operation("+")