Python: Calculating Area & Perimeter of Quadrilaterals

Quadrilaterals are polygons with four sides. They come in different types — square, rectangle, parallelogram, rhombus, trapezium (trapezoid), and kite. Each has unique formulas for area and perimeter.

In this tutorial, we’ll:

  1. Review the formulas for each quadrilateral.
  2. Write Python functions to calculate area and perimeter.
  3. Test our functions with examples.

 

Step 1: Understanding the Formulas

Here’s a quick reference table:


 

Step 2: Writing Python Functions

We’ll create modular functions — one for each quadrilateral.

 

# Square

def square(side):

    area = side ** 2

    perimeter = 4 * side

    return area, perimeter

 

# Rectangle

def rectangle(length, width):

    area = length * width

    perimeter = 2 * (length + width)

    return area, perimeter

 

# Parallelogram

def parallelogram(base, side, height):

    area = base * height

    perimeter = 2 * (base + side)

    return area, perimeter

 

# Rhombus

def rhombus(diagonal1, diagonal2, side):

    area = (diagonal1 * diagonal2) / 2

    perimeter = 4 * side

    return area, perimeter

 

# Trapezium

def trapezium(a, b, c, d, height):

    area = 0.5 * (a + b) * height

    perimeter = a + b + c + d

    return area, perimeter

 

# Kite

def kite(diagonal1, diagonal2, side1, side2):

    area = (diagonal1 * diagonal2) / 2

    perimeter = 2 * (side1 + side2)

    return area, perimeter

 

Step 3: Testing the Functions

Code:

print("Square:", square(5))             # side = 5

print("Rectangle:", rectangle(10, 6))   # length = 10, width = 6

print("Parallelogram:", parallelogram(8, 5, 4)) # base=8, side=5, height=4

print("Rhombus:", rhombus(6, 8, 5))     # diagonals=6,8; side=5

print("Trapezium:", trapezium(10, 6, 5, 7, 4)) # sides=10,6,5,7; height=4

print("Kite:", kite(8, 6, 5, 7))        # diagonals=8,6; sides=5,7

 

Step 4: Output

Square: (25, 20)

Rectangle: (60, 32)

Parallelogram: (32, 26)

Rhombus: (24.0, 20)

Trapezium: (32.0, 28)

Kite: (24.0, 24)

 



Key Takeaways

  • Each quadrilateral has unique formulas — understanding them is crucial before coding.
  • Python functions make calculations modular and reusable.
  • You can extend this tutorial by:
    • Adding user input (input() function).
    • Creating a menu-driven program to choose the quadrilateral.
    • Visualizing shapes with Matplotlib for better learning.