Python Program to Find Isosceles Triangle Area

In the previous article, we have discussed Python Program to Find Volume and Surface Area of Sphere
Isosceles triangle :

An isosceles triangle is a triangle with two equal-length sides in geometry.It is sometimes stated as having exactly two equal-length sides and other times as having at least two equal-length sides, with the latter containing the equilateral triangle as a particular scenario.

Formula :

The formula to find the area of an isosceles triangle = (y * math.sqrt((4 * x * x) – (y * y)))/4;

where x , y are the two side lengths of an isosceles triangle.

Given two sides of an isosceles triangle and the task is to find the area of the given isosceles triangle.

Examples:

Example1:

Input:

Given length of first side = 5
Given length of second side = 9

Output:

The Given Isosceles Triangle area with sides [ 5 , 9 ]= 9.808

Example2:

Input:

Given length of first side =  12
Given length of second side = 17.2

Output:

The Given Isosceles Triangle area with sides [ 12 , 17.2 ]= 71.973

Program to Find Isosceles Triangle Area

Below are the ways to find the area of the given isosceles triangle:

Method #1: Using Mathematical Formula (Static Input)

Approach:

  • Import math module using the import keyword.
  • Give the length of the first side of an isosceles triangle as static input and store it in a variable.
  • Give the length of the second side of an isosceles triangle as static input and store it in another variable.
  • Calculate the length of the given isosceles triangle using math.sqrt() function and the above given mathematical formula.
  • Store it in another variable.
  • Print the area of the given isosceles triangle.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the length of the first side of an isosceles triangle as static input
# and store it in a variable.
fst_side = 5
# Give the length of the second side of an isosceles triangle as static input
# and store it in another variable.
secnd_side = 9
# Calculate the length of the given isosceles triangle using math.sqrt() function
# and the above given mathematical formula.
# Store it in another variable.
area_isosce_tringl = (
    secnd_side * math.sqrt((4 * fst_side * fst_side) - (secnd_side * secnd_side)))/4
# Print the area of the given isosceles triangle.
print("The Given Isosceles Triangle area with sides [",
      fst_side, ",", secnd_side, "]= %.3f" % area_isosce_tringl)

Output:

The Given Isosceles Triangle area with sides [ 5 , 9 ]= 9.808

Method #2: Using Mathematical Formula (User Input)

Approach:

  • Import math module using the import keyword.
  • Give the length of the first side of an isosceles triangle as user input using the float(input()) function and store it in a variable.
  • Give the length of the second side of an isosceles triangle as user input using the float(input()) function and store it in another variable.
  • Calculate the length of the given isosceles triangle using math.sqrt() function and the above given mathematical formula.
  • Store it in another variable.
  • Print the area of the given isosceles triangle.
  • The Exit of the Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the length of the first side of an isosceles triangle as user input using the float(input()) 
#function and store it in a variable.
fst_side = float(input("Enter some random number = "))
# Give the length of the second side of an isosceles triangle as user input using the float(input())
#function and store it in another variable.
secnd_side =  float(input("Enter some random number = "))
# Calculate the length of the given isosceles triangle using math.sqrt() function
# and the above given mathematical formula.
# Store it in another variable.
area_isosce_tringl = (
    secnd_side * math.sqrt((4 * fst_side * fst_side) - (secnd_side * secnd_side)))/4
# Print the area of the given isosceles triangle.
print("The Given Isosceles Triangle area with sides [",
      fst_side, ",", secnd_side, "]= %.3f" % area_isosce_tringl)

Output:

Enter some random number = 15
Enter some random number = 22.5
The Given Isosceles Triangle area with sides [ 15.0 , 22.5 ]= 111.618

The area is isosceles is calculated by the above formula.

Explore more instances related to python concepts from Python Programming Examples Guide and get promoted from beginner to professional programmer level in Python Programming Language.