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):

  def add(self):
    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 

Sum : 9
Subtraction : 1
Multiplication : 20
Division : 1.25

Answer these Questions

  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
Tutorial on Class Object & Method Exercise constructor ( basic )
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer