Python Practice › If-Else Programs › Program 36
Scalene triangle check
Write a Python program to check whether a triangle is scalene (all three sides different).
Input
(10, 15, 18), (10, 15, 10)
Output
(10, 15, 18) is scalene (10, 15, 10) is not scalene
Approach
- All sides are different when no two are equal.
Solution
for a, b, c in [(10, 15, 18), (10, 15, 10)]: if a != b and b != c and a != c: print((a, b, c), "is scalene") else: print((a, b, c), "is not scalene")Output
(10, 15, 18) is scalene (10, 15, 10) is not scalene
Line by line
Line 2
All three pairs must differ; len({a, b, c}) == 3 is a shorter test.
Learn the concept
New to this topic? Read the lesson, then come back.