Problem 132025 · easy · Level 01 Prerequisites & Setup

What Kind of Triangle?

functions · geometry · conditionals

Write triangle_type(a, b, c) that takes three side lengths and returns:

  • "invalid" if the sides cannot form a triangle (any side is not positive, or the two shorter sides do not add up to more than the longest),
  • "equilateral" if all three sides are equal,
  • "isosceles" if exactly two sides are equal,
  • "scalene" if all sides differ.

Examples

Input:  a = 3, b = 3, c = 3
Output: "equilateral"

Input:  a = 5, b = 5, c = 8
Output: "isosceles"

Input:  a = 1, b = 2, c = 3
Output: "invalid"

Constraints

  • -1000 <= a, b, c <= 1000 (integers)

Goals

  • Check the triangle inequality
  • Order the conditions so the most specific wins
Starting Python…