In the previous article, we have discussed Python Program to Calculate Volume and Surface Area of Hemisphere

Given the area(a) and the base(b) of the triangle, the task is to find the minimum height so that a triangle of least area **a** and base **b** can be formed.

Knowing the relationship between the three allows you to calculate the minimum height of a triangle with base “b” and area “a.”

The relationship between area, base, and height:

**area = (1/2) * base * height**

As a result, height can be calculated as follows:

**height = (2 * area)/ base**

**Examples:**

**Example1:**

**Input:**

Given area = 6 Given base = 3

**Output:**

The minimum height so that a triangle of the least area and base can be formed = 4

**Example2:**

**Input:**

Given area = 7 Given base = 5

**Output:**

The minimum height so that a triangle of the least area and base can be formed = 3

## Program for Minimum Height of a Triangle with Given Base and Area in Python

Below are the ways to find the minimum height so that a triangle of least area **a** and base **b** can be formed:

### Method #1: Using Mathematical Formula (Static Input)

**Approach:**

- Import math module using the import keyword.
- Give the area as static input and store it in a variable.
- Give the base as static input and store it in another variable.
- Create a function to say
**Smallest_height()**which takes the given area and base of the triangle as the arguments and returns the minimum height so that a triangle of least area and base can be formed. - Inside the function, calculate the value of (2*gvn_areaoftri)/gvn_baseoftri using the above mathematical formula and store it in another variable.
- Apply math.ceil() function to the above result and return the minimum height.
- Pass the given area and base of the triangle as the arguments to the
**Smallest_height()**function and store it in a variable. - Print the above result i.e, minimum height so that a triangle of the least area and base can be formed.
- The Exit of the Program.

**Below is the implementation:**

# Import math module using the import keyword. import math # Create a function to say Smallest_height() which takes the given area and base # of the triangle as the arguments and returns the minimum height so that a # triangle of least area and base can be formed. def Smallest_height(gvn_areaoftri, gvn_baseoftri): # Inside the function, calculate the value of (2*gvn_areaoftri)/gvn_baseoftri using # the above mathematical formula and store it in another variable. rslt = (2*gvn_areaoftri)/gvn_baseoftri # Apply math.ceil() function to the above result and return the minimum height. return math.ceil(rslt) # Give the area as static input and store it in a variable. gvn_areaoftri = 6 # Give the base as static input and store it in another variable. gvn_baseoftri = 3 # Pass the given area and base of the triangle as the arguments to the Smallest_height() # function and store it in a variable. min_heigt = Smallest_height(gvn_areaoftri, gvn_baseoftri) # Print the above result i.e, minimum height so that a triangle of the least area # and base can be formed. print("The minimum height so that a triangle of the least area and base can be formed = ", min_heigt)

**Output:**

The minimum height so that a triangle of the least area and base can be formed = 4

### Method #2: Using Mathematical Formula (User Input)

**Approach:**

- Import math module using the import keyword.
- Give the area as user input using the int(input()) function and store it in a variable.
- Give the base as user input using the int(input()) function and store it in another variable.
- Create a function to say
**Smallest_height()**which takes the given area and base of the triangle as the arguments and returns the minimum height so that a triangle of least area and base can be formed. - Inside the function, calculate the value of (2*gvn_areaoftri)/gvn_baseoftri using the above mathematical formula and store it in another variable.
- Apply math.ceil() function to the above result and return the minimum height.
- Pass the given area and base of the triangle as the arguments to the
**Smallest_height()**function and store it in a variable. - Print the above result i.e, minimum height so that a triangle of the least area and base can be formed.
- The Exit of the Program.

**Below is the implementation:**

# Import math module using the import keyword. import math # Create a function to say Smallest_height() which takes the given area and base # of the triangle as the arguments and returns the minimum height so that a # triangle of least area and base can be formed. def Smallest_height(gvn_areaoftri, gvn_baseoftri): # Inside the function, calculate the value of (2*gvn_areaoftri)/gvn_baseoftri using # the above mathematical formula and store it in another variable. rslt = (2*gvn_areaoftri)/gvn_baseoftri # Apply math.ceil() function to the above result and return the minimum height. return math.ceil(rslt) # Give the area as user input using the int(input()) function and store it in a variable. gvn_areaoftri = int(input("Enter some random number = ")) # Give the base as user input using the int(input()) function and # store it in another variable. gvn_baseoftri = int(input("Enter some random number = ")) # Pass the given area and base of the triangle as the arguments to the Smallest_height() # function and store it in a variable. min_heigt = Smallest_height(gvn_areaoftri, gvn_baseoftri) # Print the above result i.e, minimum height so that a triangle of the least area # and base can be formed. print("The minimum height so that a triangle of the least area and base can be formed = ", min_heigt)

**Output:**

Enter some random number = 7 Enter some random number = 5 The minimum height so that a triangle of the least area and base can be formed = 3

If you are learning Python then the Python Programming Example is for you and gives you a thorough description of concepts for beginners, experienced programmers.