Welcome folks today in this post we will be finding area
of rectangle using oop
concepts such as classes
and functions
in python. All the full source code of application is shown below.
Get Started
In order to get started you need to create an app.py
file and copy paste the following code
app.py
First of all we will be using classes
to find out the area of rectangle
1 2 3 4 5 6 7 8 9 10 11 12 |
class rectangle(): def __init__(self,breadth,length): self.breadth=breadth self.length=length def area(self): return self.breadth*self.length a=int(input("Enter length of rectangle: ")) b=int(input("Enter breadth of rectangle: ")) obj=rectangle(a,b) print("Area of rectangle:",obj.area()) |
And now we will be using functions
for this task
app.py
1 2 3 4 5 6 7 8 |
def areaofrectangle(length,breadth): return breadth*length a=int(input("Enter length of rectangle: ")) b=int(input("Enter breadth of rectangle: ")) area=areaofrectangle(a,b) print("Area of rectangle:",area) |
Now if you execute these two python scripts as shown below
python app.py