Scalene triangle check

EasyIf-Else Programs · 36 of 64

Write a Python program to check whether a triangle is scalene (all three sides different).

Advertisement
Input
(10, 15, 18), (10, 15, 10)
Output
(10, 15, 18) is scalene
(10, 15, 10) is not scalene

Approach

  1. All sides are different when no two are equal.

Solution

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

Advertisement

Learn the concept

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

More if-else programs

← All 64 If-Else Programs