Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # https://www.facebook.com/groups/python/posts/1358040128369881/?#__cft__[0]=AZVWhQT874BcUFK_Nin8pNnbzSjOu2jFt8SAJuHRuRKN983HbvO5GeylsexILySHLs7IQaoY_RrOCrWPwVAu7NRZ5GPHNhyunM_427cCD4ibWHTFGRkRx_G1sbW# 8MdXJ8B457UDE-W7j7mhpjYslSO0q&__tn__=%2CO%2CP-R
- #
- from math import sqrt
- class Point:
- def __init__(self, x=0, y=0):
- self.x = x
- self.y = y
- def distancce(self, other):
- dX, dY = other.x - self.x, other.y - self.y
- return sqrt(dX**2 + dY**2)
- def __repr__(self):
- return f'({(self.x, self.y)})'
- class Circle:
- def __init__(self, center = Point(0,0), radius = 1):
- self.center = center
- self.radius = radius
- def intersects(self, other):
- return self.center.distancce(other.center) <= self.radius + other.radius
- def __lt__(self, other):
- return self.radius < other.radius
- def __repr__(self):
- return "Circle with center {}, radius {}".format(self.center, self.radius)
- # TEST
- def main(args):
- c1 = Circle()
- c2 = Circle(radius=6, center=Point(3,4))
- print("c1 = the {}".format(c1))
- print("c2 = the {}".format(c2))
- print("Their centers area {} units apart".format(c1.center.distancce(c2.center)))
- if c1.intersects(c2):
- print("The given circles intersects each other.")
- else:
- print("No intersection!")
- print("c1 is","smaller then " if c1 < c2 else "greater then","c2")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement