Python 3 Script to Find Area of Rectangle Using Classes and Functions in Object Oriented Programming Full Tutorial For Beginners

Python 3 Script to Find Area of Rectangle Using Classes and Functions in Object Oriented Programming Full Tutorial For Beginners

 

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

See also  Python 3 Matplotlib Library Script to Plot a Scatter Graph From Points DataFrame Full Project For Beginners

 

app.py

 

First of all we will be using classes to find out the area of rectangle

 

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

 

 

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)

 

See also  Python 3 Tkinter Calendar Module Widget to Display Dates inside a Dropdown Monthly,Yearly and Date Calendar GUI Desktop Full Project For Beginners

 

Now if you execute these two python scripts as shown below

 

python app.py

 

 

Leave a Reply