-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculatorr.py
More file actions
30 lines (27 loc) · 944 Bytes
/
Copy pathcalculatorr.py
File metadata and controls
30 lines (27 loc) · 944 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
""" creating a calculator """
from calculator import subtract,add,multiply,divide
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"subtraction:{subtract(int(self.n1),int(self.n2))}")
elif op=="*":
print(f"multiplication:{multiply(int(self.n1),int(self.n2))}")
elif op=="/":
print(f"divide:{divide(int(self.n1),int(self.n2))}")
def add(self):
return self.n1+self.n2
def subtract(self):
return self.n1-self.n2
def multiply(self):
return self.n1*self.n2
def divide(self):
return self.n1/self.n2
def get_input(self):
op = input("enter the operator:")
n1 = int(input("enter the first number:"))
n2 = int(input("enter the second number:"))