Decide what kind of triangle three lengths make.
What to build
A program in which one check must come before all the others.
Requirements
- Print
invalidif the three lengths cannot make a triangle. - Otherwise, print
equilateralif all three are equal. - Otherwise, print
isoscelesif any two are equal. - Otherwise, print
scalene.
Input
Three lines, each with one whole number.
Output
One word.
Constraints
Each length is from 1 to 1000.
Example
Input:
3
4
5
Output:
scalene
Why it works
If the longest side is at least as long as the other two together, the sides cannot meet, so that test has to come first. The equal-sides tests run from the most specific to the least.
Examples
Example 1 · Input
3 4 5
Expected output
scalene
Example 2 · Input
2 2 2
Expected output
equilateral
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Check first whether a triangle is possible at all.
Hint 2
Three sides make a triangle only if each pair adds up to more than the third.
Hint 3
Test all three equal before testing any two equal.
Solution
Show one correct solution (try it yourself first)
a = int(input())
b = int(input())
c = int(input())
if a + b <= c or a + c <= b or b + c <= a:
print("invalid")
elif a == b and b == c:
print("equilateral")
elif a == b or b == c or a == c:
print("isosceles")
else:
print("scalene")