To create an abstract class named Shape with an abstract method calculate_area, and implement this method in two subclasses: Rectangle and Circle.
- 
Import ABC module: - Use from abc import ABC, abstractmethod to define abstract classes and methods.
 
- 
Create Abstract Class Shape: - Define an abstract method calculate_area() with @abstractmethod.
 
- 
Create Subclass Rectangle: - Set default values for length and breadth.
- Override calculate_area() to compute the rectangle area.
 
- 
Create Subclass Circle: - Set default value for radius.
- Override calculate_area() to compute the circle area.
 
- 
Create Objects & Call Methods: - Instantiate Rectangle and Circle.
- Call their calculate_area() methods.
 
class Shape(ABC):
    def calculate_area(self):
        pass
class Rectangle(Shape):
    length = 5
    breadth =3 
    def calculate_area(self):
        return self.length * self.breadth
class Circle(Shape):
  radius = 4
  def calculate_area(self):
      return 3.14 * self.radius * self.radius
rec=Rectangle()
rec.calculate_area()
cir=Circle()
cir.calculate_area()
print("Area of a rectangle:", rec.calculate_area()) #call to 'calculate_area' method defined inside the class 'Rectangle'
print("Area of a circle:", cir.calculate_area()) #call to 'calculate_area' method defined inside the class 'Circle'.
The program successfully calculates area of shapes using abstarct method and classes
To create an abstract class named Shape with an abstract method calculate_area, and implement this method in two subclasses: Rectangle and Circle.
- 
Import ABC module: - Use from abc import ABC, abstractmethod to define abstract classes and methods.
 
- 
Create Abstract Class Shape: - Define an abstract method calculate_area() with @abstractmethod.
 
- 
Create Subclass Rectangle: - Set default values for length and breadth.
- Override calculate_area() to compute the rectangle area.
 
- 
Create Subclass Circle: - Set default value for radius.
- Override calculate_area() to compute the circle area.
 
- 
Create Objects & Call Methods: - Instantiate Rectangle and Circle.
- Call their calculate_area() methods.
 
class Shape(ABC):
    def calculate_area(self):
        pass
class Rectangle(Shape):
    length = 5
    breadth =3 
    def calculate_area(self):
        return self.length * self.breadth
class Circle(Shape):
  radius = 4
  def calculate_area(self):
      return 3.14 * self.radius * self.radius
rec=Rectangle()
rec.calculate_area()
cir=Circle()
cir.calculate_area()
print("Area of a rectangle:", rec.calculate_area()) #call to 'calculate_area' method defined inside the class 'Rectangle'
print("Area of a circle:", cir.calculate_area()) #call to 'calculate_area' method defined inside the class 'Circle'.
The program successfully calculates area of shapes using abstarct method and classes
To write a Python program that demonstrates class inheritance by creating a parent class Fish with a method type, and a child class Shark that overrides the type method.
- Define the Fish class with a method named type() that prints "fish".
- Define the Shark class as a subclass of Fish, and override the type() method to print "shark".
- Create an instance of the Fish class named obj_goldfish.
- Create an instance of the Shark class named obj_hammerhead.
- Use a for loop to iterate over both objects.
- Within the loop, call the type() method using the loop variable.
- Output will demonstrate method overriding: printing "fish" and "shark" accordingly.
class Fish:
       def type(self):
           print("fish")
class Shark(Fish):
	   def type(self):
	       print("shark")
obj_goldfish=Fish()
obj_hammerhead=Shark()
#Call the functions for fish and shark class using the objects
obj_goldfish.type()
obj_hammerhead.type()
The program successfully creates class inheritance
To write a Python program that demonstrates operator overloading by overloading the less than (<) operator using a custom class.
- 
Create Class A: - Define the init() method to initialize the object with a value a.
 
- 
Overload the < Operator: - Define the lt() method with logic:
- If self.a < o.a, return "ob1 is less than ob2"
- Else, return "ob2 is less than ob1"
 
 
- Define the lt() method with logic:
- 
Create Objects: - Instantiate two objects ob1 and ob2 with values.
 
- 
Use < Operator: - Use print(ob1 < ob2) to trigger the overloaded behavior.
 
class A:
    def _init_(self, value):
        self.value = value
    def _lt_(self, other):
        return self.value < other.value
ob1 = A(200)
ob2 = A(30)
if ob1 < ob2:
    print("ob1 is less than ob2")
else:
    print("ob2 is less than ob1")
The program successfully demonstrates operator overloading by redefining the less than (<) operator in a custom class. When comparing two objects, the overloaded method lt() executes, producing a descriptive comparison result instead of a boolean value.
To create two specific classes β Beans and Mango. Then, create a generic function that can accept any object and determine its type (Fruit or Vegetable) and color, using polymorphism.
- 
Create Class Beans: - Define type() method that prints "Vegetable".
- Define color() method that prints "Green".
 
- 
Create Class Mango: - Define type() method that prints "Fruit".
- Define color() method that prints "Yellow".
 
- 
Define Generic Function func(obj): - Call obj.type() and obj.color() β this works with both Beans and Mango objects, showcasing polymorphism.
 
- 
Create Objects: - Instantiate Beans and Mango.
- Pass them to func() and execute the program.
 
class Beans(): 
    def f(self):
        print("Vegetable")
        print("Green")
class Mango(): 
    def d(self):
        print("Fruit")
        print("Yellow")
     #Add your code here      
def func(obj): 
    pass
       #Add your code here
#creating objects
o = Beans() 
o.f()
ob = Mango() 
ob.d()
The program successfully creates class and returns type using polymorphism



