Python Program to Check Validity of Triangle Given Three Angles
This program checks whether given three angles of a triangle forms a valid triangle or not.
A triangle is valid if the sum of the three angles is equal to 180 degree and none of the angle is 0.
If a, b and c are three angles of triangle then following conditions must be satisfied for a valid triangle.
a + b + c = 180°
a ≠ 0
b ≠ 0
c ≠ 0
Python Source Code : Validity of Triangle Given Angles
# Validity of Triangle given angles
# Function definition to check validity
def is_valid_triangle(a,b,c):
if a+b+c==180 and a!=0 and b!=0 and c!=0:
return True
else:
return False
# Reading Three Angles
angle_a = float(input('Enter angle a: '))
angle_b = float(input('Enter angle b: '))
angle_c = float(input('Enter angle c: '))
# Function call & making decision
if is_valid_triangle(angle_a, angle_b, angle_c):
print('Triangle is Valid.')
else:
print('Triangle is Invalid.')
Python Output: Validity of Triangle
Run 1: --------------- Enter angle a: 78 Enter angle b: 12 Enter angle c: 89 Triangle is Invalid. Run 2: --------------- Enter angle a: 60 Enter angle b: 60 Enter angle c: 60 Triangle is Valid.