Written: August 22, 2026
Two common classroom versions exist: area from base and height (½·b·h), and area from three sides with Heron’s formula. Both are short and good input-validation practice.
Base and height
base = float(input("Base: "))
height = float(input("Height: "))
area = 0.5 * base * height
print(f"Area = {area:.2f}")
Heron’s formula
import math
a = float(input("Side a: "))
b = float(input("Side b: "))
c = float(input("Side c: "))
s = (a + b + c) / 2
area = math.sqrt(s * (s - a) * (s - b) * (s - c))
print(f"Area = {area:.2f}")
Reject inputs that cannot form a triangle (triangle inequality) before calling sqrt, or you will hit a math domain error.
Keep learning
If this walkthrough on python triangle area helped, open the code again and change one input or assumption. Small experiments beat rereading the same example.
Want more step-by-step tutorials like this? Browse blog.xqa.io — and tell us which topic you want next.