# Triangle.py - A simple class used to determine basic # geometric triangle types. # # Copyright (C) 2006,2007,2008 Mark Nenadov # # This program is free software; you can redistribute # it and/or modify it under the terms of the GNU General # Public License as published by the Free Software # Foundation; either version 2 of the License, or (at your # option) any later version. # # This program is distributed in the hope that it will # be useful, but WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. See the GNU General Public # License for more details. # # You should have received a copy of the GNU General # Public License along with this program; if not, # write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. true, false = 1, 0 def is_angle_acute(deg): if (deg > 0) and (deg < 90): return true return false class Triangle: a = [0, 0, 0] # angles s = [0, 0, 0] # sides def isValid(self): if (self.a[0] + self.a[1] + self.a[2]) != 180: return false return true def isScalene(self): if (self.s[0] == self.s[1]): return false elif (self.s[0] == self.s[2]): return false elif (self.s[1] == self.s[2]): return false return true def isIsosceles(self): if self.s[0] == self.s[1]: if self.s[0] != self.s[2]: return true if self.s[0] == self.s[2]: if self.s[0] != self.s[1]: return true if self.s[1] == self.s[2]: if self.s[1] != self.s[0]: return true def isEquilateral(self): if (self.s[0] == self.s[1] == self.s[2]): return true return false def isEquiangular(self): if (self.a[0] == self.a[1] == self.a[2]): return true return false def isRight(self): if 90 in self.a: return true return false def isObtuse(self): if self.a[0] > 90: return true elif self.a[1] > 90: return true elif self.a[2] > 90: return true return false def isAcute(self): if is_angle_acute(self.a[0]): if is_angle_acute(self.a[1]): if is_angle_acute(self.a[2]): return true return false ## Sample Code ## t = Triangle() t.a = [30, 30, 120] t.s = [55, 65, 55] if t.isValid(): if t.isAcute(): print("This triangle is Acute") if t.isRight(): print("This triangle is Right") if t.isObtuse(): print("This triangle is Obtuse") if t.isScalene(): print("This triangle is Scalene") if t.isIsosceles(): print("This triangle is Isosceles") if t.isEquilateral(): print("This triangle is Equilateral") if t.isEquiangular(): print("This triangle is Equiangular") else: print("This triangle is invalid. Try again")