supports methods:Constructor that takes as input a pair of Point objects that represent the endpoints, returns the length of the segment, and returns the slope of the segment or None if the slope is unbounded. This is what I have so far, but I keep getting an error saying unable to detect undefined names.
import math
from Point import *
class Segment:
def __init__(self,point1, point2):
self.p1 = point1
self.p2 = point2
def length(self):
x1,x2 = self.p1.getx(),self.p2.getx()
y1,y2 = self.p1.gety(), self.p2.gety()
d = (x1**2 - x2**2) + (y1**2 - y2**2)
d = math.sqrt(d)
return d
This is how the results should come out like:
p1 = Point(3,4)
p2 = Point()
s = Segment (p1, p2)
s.length()
5.0
s.slope()
0.75