Lecture Notes on 11 Sep 2020 def test_cases (): assert encrypt ('a') == 'a' assert encrypt ('ab') == 'ab' assert encrypt ('abc') == 'cab' assert encrypt ('abcd') == 'cadb' import math class Point (object): # constructor def __init__ (self, x = 0, y = 0): self.x = x self.y = y # get the distance to another Point object def dist (self, other): return math.hypot (self.x - other.x, self.y - other.y) # string representation of a Point def __str__ (self): return '(' + str(self.x) + ', ' + str(self.y) + ')' # test for equality of two Point objects def __eq__ (self, other): tol = 1.0e-6 return ((abs(self.x - other.x) < tol) and (abs(self.y - other.y) < tol)) class Circle (object): # constructor def __init__ (self, radius = 1, x = 0, y = 0): self.radius = radius self.center = Point (x, y) # compute the circumference def circumference (self): return 2 * math.pi * self.radius # compute the area def area (self): return math.pi * self.radius * self.radius # determine if a Point p is strictly inside the circle def point_inside (self, p): return self.center.dist(p) < self.radius # determine if a Circle c is strictly inside this circle def circle_inside (self, c): dist_centers = self.center.dist (c.center) return (dist_centers + c.radius) < self.radius # determine if a Circle c intersects this circle # Circle c has non-zero area inside and # non-zero area outside this circle def circle_intersects (self, c): dist_centers = self.center.dist (c.center) is_inside = (dist_centers + c.radius) < self.radius is_outside = dist_centers > (self.radius + c.radius) return (not is_inside) and (not is_outside) def main(): # create Point objects a = Point (3, 4) b = Point (3, 4) # print the Point objects print (a) print (b) # get distances print (a.dist(b)) print (b.dist(a)) # test for equality print (a == b) main()