# Calculator using OOPs

1. Basic Exercise on Object Oriented Programming
2. Create one class calculator
3. While creating object of calculator class take two user inputs.
4. Display addition , subtraction, multiplication and division of two input numbers.

Exercise Solution
``````class calculator():
def __init__(self,x,y):
self.x=x
self.y=y

print("Sum :",self.x+self.y)

def subtraction(self):
print("Subtraction :",self.x-self.y)

def multiplication(self):
print("Multiplication :",self.x*self.y)

def division(self):
print("Division :",self.x/self.y)
#x=int(input("Enter first number : "))
#y=int(input("Enter second number : "))
#n1=calculator(x,y) # object
n1=calculator(5,4) # object

n1.subtraction()
n1.multiplication()
n1.division()``````
Output
``````Sum : 9
Subtraction : 1
Multiplication : 20
Division : 1.25``````

1. What is the name of the method used in calculator class ?
2. List all objects created in above code ?
3. What is the data type of created object

## Subscribe

* indicates required
Subscribe to plus2net plus2net.com