Isosceles triangle check

EasyIf-Else Programs · 37 of 64

Write a Python program to check whether a triangle is isosceles (at least two equal sides).

Advertisement
Input
(10, 15, 10), (8, 9, 10)
Output
(10, 15, 10) is isosceles
(8, 9, 10) is not isosceles

Approach

  1. Any one pair of equal sides is enough, so join the checks with or.

Solution

Python
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.

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More if-else programs

← All 64 If-Else Programs