194k views
1 vote
Input 3 positive integers from the terminal, determine if tlrey are valid sides of a triangle. If the sides do form a valid triangle, output the type of triangle - equilateral, isosceles, or scalene - and the area of the triangle. If the three integers are not the valid sides of a triangle, output an appropriats message and the 3 sides. Be sure to comment and error check in your progam.

1 Answer

6 votes

Answer:

In Python:

side1 = float(input("Side 1: "))

side2 = float(input("Side 2: "))

side3 = float(input("Side 3: "))

if side1>0 and side2>0 and side3>0:

if side1+side2>=side3 and side2+side3>=side1 and side3+side1>=side2:

if side1 == side2 == side3:

print("Equilateral Triangle")

elif side1 == side2 or side1 == side3 or side2 == side3:

print("Isosceles Triangle")

else:

print("Scalene Triangle")

else:

print("Invalid Triangle")

else:

print("Invalid Triangle")

Step-by-step explanation:

The next three lines get the input of the sides of the triangle

side1 = float(input("Side 1: "))

side2 = float(input("Side 2: "))

side3 = float(input("Side 3: "))

If all sides are positive

if side1>0 and side2>0 and side3>0:

Check if the sides are valid using the following condition

if side1+side2>=side3 and side2+side3>=side1 and side3+side1>=side2:

Check if the triangle is equilateral

if side1 == side2 == side3:

print("Equilateral Triangle")

Check if the triangle is isosceles

elif side1 == side2 or side1 == side3 or side2 == side3:

print("Isosceles Triangle")

Otherwise, it is scalene

else:

print("Scalene Triangle")

Print invalid, if the sides do not make a valid triangle

else:

print("Invalid Triangle")

Print invalid, if the any of the sides are negative

else:

print("Invalid Triangle")

User Ximena
by
6.9k points