class Student: '''A student with a name, age, and major.''' def __init__(self, name, age, major): '''Initializes the student object.''' self.name = name self.age = age self.major = major def birthyear(self): '''Return the student's year of birth.''' return 2016 - self.age def switch_major(self, new_major): '''Changes the student's major to new_major''' self.major = new_major ######################## import math class Point: # or equivalently, class Point(object): '''Represent an (x, y) coordinate pair.''' def __init__(self, new_x, new_y): '''Set up a new Point object with an x and y value.''' self.x = new_x self.y = new_y def distance_to(self, other_point): '''Return the distance from this point to other_point.''' x1 = self.x y1 = self.y x2 = other_point.x y2 = other_point.y return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) def distance_origin(self): '''Return the distance from this point (aka self) to the origin.''' origin = Point(0, 0) return self.distance_to(origin) class LineSegment: '''A line segment from one point to another point.''' def __init__(self, start_point, end_point): '''Initializes the line segment by storing the start and endpoints.''' self.start_point = start_point self.end_point = end_point def slope(self): '''Return the slope of the line segment.''' change_y = self.end_point.y - self.start_point.y change_x = self.end_point.x - self.start_point.x return change_y / change_x def length(self): '''Return the length of the line segment.''' return self.start_point.distance_to(self.end_point)