Python Practice › If-Else Programs › Program 37
Isosceles triangle check
Write a Python program to check whether a triangle is isosceles (at least two equal sides).
Input
(10, 15, 10), (8, 9, 10)
Output
(10, 15, 10) is isosceles (8, 9, 10) is not isosceles
Approach
- Any one pair of equal sides is enough, so join the checks with
or.
Solution
for a, b, c in [(10, 15, 10), (8, 9, 10)]: if a == b or b == c or a == c: print((a, b, c), "is isosceles") else: print((a, b, c), "is not isosceles")Output
(10, 15, 10) is isosceles (8, 9, 10) is not isosceles
Line by line
Line 2
or is true if any pair matches. By this definition an equilateral triangle is also isosceles.
Learn the concept
New to this topic? Read the lesson, then come back.