Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Determine Triangle Type

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

Python practice25 minControl Flow (If–Else Logic)AdvancedLast updated March 15, 2026

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

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 1

Input

triangle_type(2, 2, 2)

Output

equilateral

All three sides equal.