Triangle Type Classifier

Hard ⏱ 18 min 39% acceptance ★★★★★ 4.9
Write a function triangle_type(a, b, c) that first checks whether the three side lengths form a valid triangle (see triangle inequality). If invalid, return "Not a triangle". Otherwise return "Equilateral" if all three sides are equal, "Isosceles" if exactly two sides are equal, or "Scalene" if all sides differ.

Examples

Example 1
Input
triangle_type(5, 5, 5)
Output
"Equilateral"
Explanation

All sides equal and forms a valid triangle.

Example 2
Input
triangle_type(5, 5, 8)
Output
"Isosceles"
Explanation

Two sides equal, valid triangle.

Example 3
Input
triangle_type(1, 1, 5)
Output
"Not a triangle"
Explanation

1+1 is not greater than 5.

Constraints

  • a, b, c are positive numbers.

Topics

Conditional Statementsnested conditionals

Companies

OracleDeloitte

Hints

Hint 1

Validate the triangle inequality before classifying the type.

Hint 2

Count how many of the three pairwise equalities hold, or compare directly with nested ifs.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.