easy +8 pts

Classify triangle by sides

Determine whether three side lengths form an equilateral, isosceles, scalene, or invalid triangle.

Write a function `classify_triangle(a, b, c)` that takes three positive numbers representing the side lengths of a triangle. The function should return a string: - `"equilateral"` if all three sides are equal and form a valid triangle. - `"isosceles"` if exactly two sides are equal and the triangle is valid. - `"scalene"` if all sides are different and the triangle is valid. - `"invalid"` if the sides do not form a valid triangle. A triangle is valid if and only if each side is positive and the sum of any two sides is greater than the third side. For example, `(1, 2, 3)` is invalid because `1 + 2` is not greater than `3`. The input sides can be integers or floats. The output must be exactly one of the strings listed above.

Constraints

Input values are numbers (int or float). They may be zero or negative. No input will be non-numeric. The function should run in O(1) time and O(1) space.

Example

>>> classify_triangle(2, 2, 2)
'equilateral'
>>> classify_triangle(3, 3, 5)
'isosceles'
>>> classify_triangle(4, 5, 6)
'scalene'
>>> classify_triangle(1, 2, 3)
'invalid'
8 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

First check if the sides are positive and satisfy the triangle inequality.
Count how many sides are equal to determine the type.
Remember that all sides must be positive; zero or negative sides are automatically invalid.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.