Logic Building
# Take three sides as input
a = float(input("Enter side 1: "))
b = float(input("Enter side 2: "))
c = float(input("Enter side 3: "))
# Check if valid triangle
if a + b > c and b + c > a and c + a > b:
print("Valid triangle")
else:
print("Invalid triangle")Output
Enter side 1: 3 Enter side 2: 4 Enter side 3: 5 Valid triangle Enter side 1: 1 Enter side 2: 2 Enter side 3: 5 Invalid triangle
Triangle inequality theorem: Sum of any two sides must be greater than the third side.
Key Concepts:
- Check all three combinations: a+b>c, b+c>a, c+a>b
- Use
andto ensure all conditions are met - All three conditions must be True for a valid triangle