Python Program to calculate the area of the rhombus


A rhombus is a four-sided polygon that has all equal edges and perpendicular diagonals. It is also called as a special type of parallelogram, since a parallelogram has equal opposite sides and is shaped similar.

The area of a rhombus is calculated with its diagonals, as they form four triangles within the figure. The combination of the area of all those triangles will give us the area of a rhombus. The mathematical formula is −

Area − $\mathrm{{\frac{p\:\times\:q}{2}}}$

Where, p and q are the lengths of diagonals.

Input Output Scenarios

Let us look at some input output scenarios to calculate the area and volume of a sphere −

Assume the product of diagonals is odd, the output is −

Input: (3, 5) // length of diagonals
Result: Area – 7.5

Assume the product of diagonals is even, the output is −

Input: (6, 8) // length of diagonals
Result: Area – 24.0

Using Mathematical Formula

We can implement a python program that calculates the area of a rhombus using its standard mathematical formula, with the only input requirements being the length of its diagonals.

Example

The following example shows the python implementation of computing a rhombus area −

#length of rhombus diagonals p = 6 q = 8 #calculating area of rhombus area = (p*q) / 2 #displaying output print("Area of the Rhombus: ", str(area))

Output

On compiling and executing the above python code, the output is obtained as −

Area of the Rhombus: 24.0

Function to calculate Area of the Rhombus

We can also use user-defined functions in python to implement calculating the area of rhombus. The def keyword is used to define a function that contains lines of code to produce the output.

Example

The following python code uses user-defined functions to find rhombus area −

def rhombus_area(p, q): #calculating area of rhombus area = (p*q) / 2 #displaying output print("Area of the Rhombus: ", str(area)) #length of rhombus diagonals p = 6 q = 8 rhombus_area(p, q)

Output

The output is obtained as follows −

Area of the Rhombus: 24.0

Updated on: 26-Oct-2022

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements