Triangle Type Check
Determine if three sides form a valid triangle and its type (equilateral, isosceles, scalene).
BeginnerTopic: Conditional Programs
Python Triangle Type Check Program
This program helps you to learn the fundamental structure and syntax of Python programming.
# Program to check triangle validity and type
a = float(input("Enter first side: "))
b = float(input("Enter second side: "))
c = float(input("Enter third side: "))
if a <= 0 or b <= 0 or c <= 0:
print("Sides must be positive.")
elif a + b <= c or a + c <= b or b + c <= a:
print("Not a valid triangle.")
else:
if a == b == c:
print("Equilateral triangle")
elif a == b or a == c or b == c:
print("Isosceles triangle")
else:
print("Scalene triangle")Output
Enter first side: 3 Enter second side: 4 Enter third side: 5 Scalene triangle
Understanding Triangle Type Check
First we apply the triangle inequality to check validity.
Then we compare side lengths to classify as equilateral, isosceles, or scalene.
Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.