forked from kriru/firstJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.py
More file actions
38 lines (36 loc) · 1017 Bytes
/
calculator.py
File metadata and controls
38 lines (36 loc) · 1017 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
class cal():
def __init__(self,a,b):
self.a=a
self.b=b
def add(self):
return self.a+self.b
def mul(self):
return self.a*self.b
def div(self):
return self.a/self.b
def sub(self):
return self.a-self.b
a=int(input("Enter first number: "))
b=int(input("Enter second number: "))
obj=cal(a,b)
choice=1
print("0. Exit")
print("1. Add")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
while choice!=0:
choice=int(input("Enter choice: "))
if choice==1:
print("Sum of entered numbers is : ",obj.add())
elif choice==2:
print("Subtraction of entered numbers is: ",obj.sub())
elif choice==3:
print("Multiplication result of numbers is: ",obj.mul())
elif choice==4:
print("Division of entered numbers is : ",round(obj.div(),2))
elif choice==0:
print("Exiting!")
else:
print("Invalid, Please enter valid choice!!")
print()