Triangle Valid Not Program in Python


Write a program to check whether a triangle is valid or not, when the three angles of the triangle are entered through the keyboard. A triangle is valid if the sum of all the three angles is equal to 180 degrees.

This program is a basic implementation of a program that checks if a given triangle is valid or not. The program first prompts the user to input the three sides of a triangle (s1, s2, and s3) using the "input" function. These input values are then stored as integer variables. The program then calculates the sum of all three sides and assigns it to the variable "sum".

Next, the program uses an "if-else" statement to check if the sum of all three sides is equal to 180. If the sum is equal to 180, it prints "Triangle Valid.." to the console. If the sum is not equal to 180, it prints "Triangle Not Valid.." to the console. This program will not work if the sum of all three sides is not 180, as the sum of all three angles in a triangle must always be 180 degrees.


Source Code

s1 = int(input("Enter the Triangle Side-1 :"))
s2 = int(input("Enter the Triangle Side-2 :"))
s3 = int(input("Enter the Triangle Side-3 :"))
sum = s1+s2+s3
if(sum==180):
	print("Triangle Valid..")
else:
	print("Triangle Not Valid..")

Output

Enter the Triangle Side-1 :40
Enter the Triangle Side-2 :50
Enter the Triangle Side-3 :60
Triangle Not Valid..

Example Programs