Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Abstraction .md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,43 @@ To create an **abstract class** named `Shape` with an **abstract method** `calcu
---

## 💻 Program
```
from abc import ABC, abstractmethod
import math


class Shape(ABC):
@abstractmethod
def calculate_area(self):
pass


class Rectangle(Shape):
def __init__(self, length=5, breadth=4):
self.length = length
self.breadth = breadth

def calculate_area(self):
return self.length * self.breadth


class Circle(Shape):
def __init__(self, radius=3):
self.radius = radius

def calculate_area(self):
return math.pi * self.radius * self.radius


rect = Rectangle()
circ = Circle()


print("Area of Rectangle:", rect.calculate_area())
print("Area of Circle:", round(circ.calculate_area(), 2))
```
## Output
![image](https://github.com/user-attachments/assets/ba3c4a39-a9f6-4d10-bde9-ec1c4279aa1a)

## Result
The area of the rectangle and circle was correctly calculated and displayed.