import math 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 birthyear of the student''' return 2015 - self.age def switch_major(self, new_major): '''Change the student's major to new_major and print a message saying it was done.''' self.major = new_major print(self.name + " changed major to " + self.major) class LineSegment: '''A line segment class consisting of two points.''' def __init__(self, point1, point2): '''Initialize the line segment between point1 and point2''' self.startpoint = point1 self.endpoint = point2 def slope(self): '''Return the slope of the line''' change_y = self.endpoint[1] - self.startpoint[1] change_x = self.endpoint[0] - self.startpoint[0] return change_y / change_x def length(self): '''Return the length of the line''' return math.sqrt( (self.endpoint[0] - self.startpoint[0]) ** 2 + (self.endpoint[1] - self.startpoint[1]) ** 2)