Created
June 9, 2014 11:42
-
-
Save jianghu52/340203cef789a7f9b5f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
class Point(object): | |
def __init__(self, x=0, y=0): | |
try: | |
int(x) + 1 | |
except TypeError: | |
self.x = 0 | |
else: | |
self.x = x | |
try: | |
int(y) + 1 | |
except TypeError: | |
self.y = 0 | |
else: | |
self.y = y | |
# | |
# test = Point(-399,"-666") | |
# print test.x | |
class Retangle(): | |
point1 = Point() | |
point2 = Point() | |
point3 = Point() | |
point4 = Point() | |
x_spce1 = abs(point1.x - point2.x) | |
y_spce1 = abs(point1.y - point2.y) | |
z_spce1 = (x_spce1 * x_spce1) + (y_spce1 * y_spce1) | |
x_spce2 = abs(point1.x - point3.x) | |
y_spce2 = abs(point1.y - point3.y) | |
z_spce2 = (x_spce2 * x_spce2) + (y_spce2 * y_spce2) | |
x_spce3 = abs(point1.x - point4.x) | |
y_spce3 = abs(point1.y - point4.y) | |
z_spce3 = (x_spce3 * x_spce3) + (y_spce3 * y_spce3) | |
def isretanle(self): | |
if max(self.z_spce1, self.z_spce2, self.z_spce3) == self.z_spce1: | |
if self.z_spce1 == self.z_spce2 + self.z_spce3: | |
return True | |
else: | |
return False | |
elif max(self.z_spce1, self.z_spce2, self.z_spce3) == self.z_spce2: | |
if self.z_spce2 == self.z_spce1 + self.z_spce3: | |
return True | |
else: | |
return False | |
elif max(self.z_spce1, self.z_spce2, self.z_spce3) == self.z_spce3: | |
if self.z_spce3 == self.z_spce1 + self.z_spce2: | |
return True | |
else: | |
return False | |
def getarea(self): | |
if self.isretanle(): | |
if max(self.z_spce1, self.z_spce2, self.z_spce3) == self.z_spce1: | |
return float((math.sqrt(self.z_spce2)) * (math.sqrt(self.z_spce3))) | |
elif max(self.z_spce1, self.z_spce2, self.z_spce3) == self.z_spce2: | |
return float((math.sqrt(self.z_spce1)) * (math.sqrt(self.z_spce3))) | |
elif max(self.z_spce1, self.z_spce2, self.z_spce3) == self.z_spce3: | |
return float((math.sqrt(self.z_spce1)) * (math.sqrt(self.z_spce2))) | |
test = Retangle() | |
test.point1=Point(5,5) | |
test.point2=Point(10,5) | |
test.point3=Point(5,-5) | |
test.point4=Point(10,-5) | |
print test.getarea |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment