Equilateral triangle check

EasyIf-Else Programs · 35 of 64

Write a Python program to check whether a triangle is equilateral (all three sides equal).

Advertisement
Input
(10, 10, 10), (10, 15, 10)
Output
(10, 10, 10) is equilateral
(10, 15, 10) is not equilateral

Approach

  1. Compare all three sides with a chained ==.

Solution

Python
for a, b, c in [(10, 10, 10), (10, 15, 10)]:    if a == b == c:        print((a, b, c), "is equilateral")    else:        print((a, b, c), "is not equilateral")
Output
(10, 10, 10) is equilateral
(10, 15, 10) is not equilateral

Line by line

Line 2

a == b == c means a == b and b == c.

Advertisement

Learn the concept

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

More if-else programs

← All 64 If-Else Programs