25 XP

36. Triangle type

Beginner conditions

Three sticks make a triangle only if each one is shorter than the other two laid end to end. With lengths 1, 2 and 3 the two short sticks only just reach across the long one, so they lie flat: that isn't a triangle.

Write a function triangle_type(a, b, c) that takes three whole numbers, the lengths of the sides, and returns one of four strings:

  • "not a triangle" if the sides can't make a triangle: some side is as long as the other two together, or longer. A side of 0 can never be part of a triangle, and this rule already rules it out.
  • "equilateral" if all three sides are the same length;
  • "isosceles" if exactly two sides are the same length;
  • "scalene" if all three lengths are different.

Check for "not a triangle" first: 2, 2 and 5 have two equal sides, but 2 + 2 is less than 5.

Example 1

Inputa = 3, b = 3, c = 3
Output"equilateral"
ExplanationAll three sides are 3.

Example 2

Inputa = 3, b = 4, c = 5
Output"scalene"
ExplanationA real triangle with three different sides.

Example 3

Inputa = 1, b = 2, c = 3
Output"not a triangle"
Explanation1 + 2 is not more than 3, so it lies flat.

Constraints

  • a, b and c are whole numbers from 0 to 1000, in any order.

Submit also runs 11 more tests you can't see.

Practises If / Elif / Else (lesson 8).

Code
def triangle_type(a, b, c):
    """Name the kind of triangle three sides make.

    a, b, c: int, the lengths of the sides, 0 to 1000
    Returns: str, "equilateral", "isosceles", "scalene" or
        "not a triangle"
    """
    # Write your code here
    pass