Menu

Sign in to track your progress and unlock all features.

Theme style

Start learning freeLog in

Problem No 19

Determine Triangle Type

Hard

≈ 25 minute session

Summary

Given three side lengths, determine whether they form a valid triangle and classify it.

Problem statement

Write a function triangle_type(a, b, c) that takes three numbers representing side lengths and returns a string describing the triangle type. Rules: - If any side length is less than or equal to 0, return "not a triangle". - If the three lengths do not satisfy the strict triangle inequality (a + b > c, a + c > b, b + c > a), return "not a triangle". (Degenerate cases where equality holds are not triangles.) - If all three sides are equal, return "equilateral". - If exactly two sides are equal, return "isosceles". - If all sides are different and form a valid triangle, return "scalene". The function should accept integers or floats and return one of the exact strings: "equilateral", "isosceles", "scalene", or "not a triangle".

Task

Practice complex conditional logic: validate numeric input, enforce triangle inequality, and categorize triangles as equilateral, isosceles, scalene, or not a triangle.

Examples

Classic 3-4-5 triangle is scalene

Input

triangle_type(3, 4, 5)

Output

scalene

Explanation

All sides different and satisfy triangle inequality, so it's scalene.

Input format

Three numeric arguments a, b, c passed to triangle_type(a, b, c).

Output format

A string: one of "equilateral", "isosceles", "scalene", or "not a triangle".

Constraints

- Sides may be integers or floats. - Treat non-positive sides and degenerate triangles (where a + b == c etc.) as "not a triangle". - Use strict comparisons for triangle inequality.

Samples

Sample input 0

triangle_type(2, 2, 2)

Sample output 0

equilateral

Explanation 0

All three sides equal.

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.