Calculating the area of a triangle is one of the basic programs often used in programming tutorials and beginner exercises. This Python program demonstrates how to calculate the area of a triangle using the standard mathematical formula involving base and height.
The formula used is:
Area = 0.5 × base × height
In this post, we will go through a step-by-step guide to writing a simple and beginner-friendly Python script to compute the area of a triangle.
Python Code to Find Area of a Triangle
# Program to calculate the area of a triangle # Input values for base and height base = float(input("Enter the base of the triangle: ")) height = float(input("Enter the height of the triangle: ")) # Calculate area area = 0.5 * base * height # Display the result print(f"The area of the triangle is: {area}")
How the Program Works
- The program first prompts the user to enter the base and height of the triangle.
- It then uses the formula
area = 0.5 * base * height
to calculate the area. - The result is displayed using Python’s
print()
function with formatted output.
Output

Why This Program Is Useful
- Helps understand the basics of input handling and arithmetic operations in Python.
- Useful for school-level programming tasks, Python practice exercises, and coding interviews.
- Demonstrates the use of floating-point operations and formatted strings.
Additional Improvements You Can Try
- Wrap the logic in a function:
def calculate_triangle_area(base, height)
- Handle invalid input using try-except blocks
- Extend the code to calculate area using Heron’s Formula for three sides
SEO Keywords and Keyphrases
- Python program to find area of triangle
- Area of triangle using base and height in Python
- Triangle area calculation in Python
- Basic Python geometry program
- Python input output example
Conclusion
This Python program is a simple and effective way to understand how to apply a mathematical formula using user inputs. By practicing such examples, beginners can build a strong foundation in Python programming. Keep exploring more beginner-level programs to strengthen your skills.