What kind of triangle? (CCC/2014/J1)

Challenge

Define a function, TriangleType, that decides if a triangle is equilateral, isosceles, or scalene (or not a triangle at all).  Your input will be three integers, each representing the measure of one interior angle.  Your output should be “equilateral”, “isosceles”, “scalene”, or “not even a triangle”.

Original problem description on CEMC website.

Sample Output:


>>> TriangleType(70, 55, 55)
"isosceles"

>>> TriangleType(1,177,2)
"scalene"

>>> TriangleType(35,27,78)
"not even a triangle"

Background Information

Every triangle has the property that the sum of its interior angles is 180 degrees.

If all of the angles of a triangle are equal to each other (i.e., they all measure 60 degrees), then the triangle is called equilateral.  If two of its angles are equal to each other, but the third is different, then the triangle is called isosceles. If all three angles are different, then the triangle is called scalene.

Programming Tools (with Python examples)

 

Defining a function.  The following example defines a function Sum which adds up three numbers a, b, and c.


def Sum(a,b,c):
    return a + b + c

Sample Output:


>>> Sum(1,2,3)
6

>>> Sum(-3,-1,4)
0

>>> Sum(3,4)
ERROR (wrong number of inputs)

 

Comparing two numbers. It is often useful to compare two numbers using “less than,” “greater than,” “equal to,” “not equal to,” “less than or equal to,” “greater than or equal to.”

Sample Output:


>>> 1 < 2
True

>>> 1 > 2
False

>>> 1 != 2
True

>>> 2 < 2
False

>>> 2 <= 2
True

>>> 2 >= 2
True

>>> 2 == 2
True

>>> 2 = 2
ERROR

>>> Sum(1,2,3) == 6
True

>>> Sum(0,1,1) != 2
False

 

Basic flow control: If/then/else.  The following function decides whether a number is less than 100, between 100 and 1000, or more than 1000.


def HowBig(x):
    if x < 100:
        return "not that big."
    elif x < 1000:
        return "big."
    else:
        return "really big."

Sample Output:


>>> HowBig(3)
"not that big."

>>> HowBig(625.34)
"big."

>>> HowBig(123456789)
"really big."

>>> HowBig('apple')
ERROR (must be a number to compare in lines 2 and 4)

Extension

Let ABCD by a quadrilateral (four-sided polygon).  Write a function to decide if ABCD is a parallelogram.  The inputs of your function will be four integers, representing the measures of the angles, in clockwise order.  Your output should be “parallelogram”, “not a parallelogram”, or “not even a quadrilateral”.