Python Program to find Area of a Triangle using base and height

Write Python Program to find Area Of a Triangle using base and height with a practical example.

Python Program to find Area of a Triangle using base and height example 1

This Python program allows the user to enter the base and height of a triangle. By using the base and height values, it finds the area of a triangle. The mathematical formula to find Area of a triangle using base and height: Area = (base * height) / 2.

# Python Program to find Area of a Triangle using base and height

base = float(input('Please Enter the Base of a Triangle: '))
height = float(input('Please Enter the Height of a Triangle: '))

# calculate the area
area = (base * height) / 2

print("The Area of a Triangle using", base, "and", height, " = ", area)
Python Program to find Area of a Triangle using base and height 1

Python Program to calculate Area of a Triangle using base and height example 2

This Python program for the area of the triangle is the same as above. However, we separated the area of triangle program logic using Python functions concept.

# Python Program to find Area of a Triangle using base and height
def area_of_triangle(base, height):
    return (base * height) / 2

base = float(input('Please Enter the Base of a Triangle: '))
height = float(input('Please Enter the Height of a Triangle: '))

# calculate the area
area = area_of_triangle(base, height)
print("The Area of a Triangle using", base, "and", height, " = ", area)

Python Area of a Triangle using base and height output

Please Enter the Base of a Triangle: 35
Please Enter the Height of a Triangle: 85
The Area of a Triangle using 35.0 and 85.0  =  1487.5

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.