Example
Input
5
4
2
Output
Traingle is valid
Required to Know
Use of Variables, Use of different operators like assignment or arithmetic operators, Use of functions like print(), and input(), Use of If-else, and Use of Data types.
Triangle Property
The sum of any two sides of the triangle must be greater than the length of the third side. Mathematically, for a triangle with sides a, b, and c, this condition can be expressed as
a+b>c
b+c>a
a+c>b
Steps
Take three sides as input from the user.
Check if the triangle is valid based on the three conditions: -
side1+side2>side3
side2+side3>side1
side1+side3>side2
Program
# Prompt the user to enter the lengths of the three sides of the triangle
side1 = int(input("Enter the length of side 1: "))
side2 = int(input("Enter the length of side 2: "))
side3 = int(input("Enter the length of side 3: "))
# Check if the triangle is valid by verifying the three conditions
is_valid = (side1 + side2 > side3) and (side2 + side3 > side1) and (side1 + side3 > side2)
# If the triangle is valid, print a message indicating its validity. Otherwise, print a message indicating it is not valid.
if is_valid:
print("Triangle is valid.")
else:
print("Triangle is not valid.")