Python Programming : check whether triangle is valid or not
Example
Input
30 60 90
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
A triangle is considered to be valid if the sum of the angles of the triangle is equal to 180.
Steps
Take three angles as input from the user.
Find the sum of all the three triangles.
check if the sum is equal to 180 degrees, then the formation of the triangle can happen, otherwise not. Also, check if all the angles are more than 0 or not.
Program
# This code checks if the three angles of a triangle add up to 180 degrees.
# Get the three angles of the triangle from the user.
angle1 = int(input("Enter the first angle: "))
angle2 = int(input("Enter the second angle: "))
angle3 = int(input("Enter the third angle: "))
# Calculate the sum of the three angles.
sum_of_angles = angle1 + angle2 + angle3
# Check if the sum of the angles is equal to 180 degrees.
if sum_of_angles == 180:
# The triangle is valid.
print("The triangle is valid.")
else:
# The triangle is not valid.
print("The triangle is not valid.")