Skip to content
Exercise · Conditions · lesson 8 of 8

Exercise: triangle kind

Write a function triangle_kind(a, b, c) that finds the kind of a triangle from the lengths of its three sides. It returns:

  • "equilateral" if all sides are equal;
  • "isosceles" if exactly two sides are equal;
  • "scalene" if all sides are different;
  • "invalid" if no triangle has such sides.

Examples:

  • triangle_kind(3, 4, 5) → "scalene"
  • triangle_kind(5, 5, 8) → "isosceles"
  • triangle_kind(1, 2, 3) → "invalid"

Constraints: the sides are integers from −100 to 100 in any order. No triangle exists if some side is not greater than zero or not less than the sum of the other two.

Do not add extra imports unless the task says so explicitly.

triangle.py — python
python · 3 lines
Ctrl+Enter run · Esc leave editor

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way