Skip to content
Snippets Groups Projects
Commit 5dc5a0b8 authored by Sepehr Bayat's avatar Sepehr Bayat
Browse files

Update TriangleADT.py

parent a1784957
No related branches found
No related tags found
No related merge requests found
......@@ -24,16 +24,16 @@ class Triangle:
# @return The sides of the triangle
def sides(self):
seq = [0,0,0]
seq[0] = self.__a.dist(self.__b)
seq[1] = self.__a.dist(self.__c)
seq[2] = self.__b.dist(self.__c)
self.seq[0] = self.__a.dist(self.__b)
self.seq[1] = self.__a.dist(self.__c)
self.seq[2] = self.__b.dist(self.__c)
return seq;
## @brief Inequality theorem
# @return the existence of a triangle
def inequality_theorem(self):
seq = self.sides()
if (seq[0] +seq[1] > seq[2] and seq[0]+seq[2] > seq[1] and seq[1]+seq[2] >seq[1]):
if (self.seq[0] +self.seq[1] > self.seq[2] and self.seq[0]+self.seq[2] > self.seq[1] and self.seq[1]+self.seq[2] >self.seq[1]):
return True;
elif (self.__a.xcoord()==self.__b.xcoord()==self.__c.xcoord() or self.__a.ycoord()==self.__b.ycoord()==self.__c.ycoord()):
return False;
......@@ -45,7 +45,7 @@ class Triangle:
def perimeter_of_triangle(self):
seq = self.sides()
if self.inequality_theorem():
return seq[0]+seq[1]+seq[2]
return self.seq[0]+self.seq[1]+self.seq[2]
else:
print("You can't have a triangle with the points")
......@@ -54,8 +54,8 @@ class Triangle:
def area_of_triangle(self):
seq = self.sides()
if self.inequality_theorem():
P = (seq[0]+seq[1]+seq[2])/2
return sqrt(P*(P-self.seq[0])*(P-seq[1])*(P-seq[2]))
P = (self.seq[0]+self.seq[1]+self.seq[2])/2
return sqrt(P*(P-self.seq[0])*(P-self.seq[1])*(P-self.seq[2]))
else:
print("You can't have a triangle with the points")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment