Write a Python Program to Check Triangle is Valid or Not using user specified angles. Remember, any triangle is valid, if sum of 3 angles in a triangle is equal to 180
Python Program to check Triangle is Valid or Not Example 1
This Python program helps the user to enter all angles of a triangle. Next, we used a Python If Else statement to check whether the sum of the given angles is equal to 180 or not. If True, the print statement prints a valid triangle. Otherwise, the Python program prints an invalid triangle.
# Python Program to check Triangle is Valid or Not
a = int(input('Please Enter the First Angle of a Triangle: '))
b = int(input('Please Enter the Second Angle of a Triangle: '))
c = int(input('Please Enter the Third Angle of a Triangle: '))
# checking Triangle is Valid or Not
total = a + b + c
if total == 180:
print("\nThis is a Valid Triangle")
else:
print("\nThis is an Invalid Triangle")

Python Program to verify Triangle is Valid or Not Example 2
In the above Python example, we forgot to check whether any of the angles is zero or not. So, we used the Python Logical AND operator to make sure all angles are greater than 0
a = int(input('Please Enter the First Angle of a Triangle: '))
b = int(input('Please Enter the Second Angle of a Triangle: '))
c = int(input('Please Enter the Third Angle of a Triangle: '))
# checking Triangle is Valid or Not
total = a + b + c
if (total == 180 and a != 0 and b != 0 and c != 0):
print("\nThis is a Valid Triangle")
else:
print("\nThis is an Invalid Triangle")
Please Enter the First Angle of a Triangle: 70
Please Enter the Second Angle of a Triangle: 70
Please Enter the Third Angle of a Triangle: 40
This is a Valid Triangle
>>>
=================== RESTART: /Users/suresh/Desktop/simple.py ===================
Please Enter the First Angle of a Triangle: 90
Please Enter the Second Angle of a Triangle: 90
Please Enter the Third Angle of a Triangle: 0
This is an Invalid Triangle
>>>
Also Read
- Python Program to Find angle of a Triangle if two angles are given
- Python Program for Isosceles Triangle Area