Part of the series

Several example codes

~1 min read • Updated Oct 1, 2025

Program Overview

This Python program reads the base and height of a triangle from the user and calculates its area.
The formula used is:
Area = (base × height) / 2


Python Code:


# Read inputs from user
base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))

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

# Display result
print("\n--- Result ---")
print(f"The area of the triangle is: {area:.2f}")

Sample Output:


Enter the base of the triangle: 10  
Enter the height of the triangle: 5  

--- Result ---  
The area of the triangle is: 25.00

Step-by-Step Explanation:

- Inputs are received as floating-point numbers
- The standard formula for triangle area is applied
- The result is printed with two decimal places


Written & researched by Dr. Shahin Siami