0

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

Justin
  • 15
  • 5
  • 1
    Can you post the full error, including the Traceback? This will help us see exactly where the error lies. – lordingtar Jul 18 '16 at 19:02
  • I tried posting a picture, but it's not letting me. But it says 'from Point import *' used; unable to detect undefined names. Then when i ran it, it gave me a traceback error saying 'No module named point' – Justin Jul 18 '16 at 19:11
  • 1
    Where is your "Point" module ? See this link : http://stackoverflow.com/questions/12468900/making-a-point-class-in-python – JazZ Jul 18 '16 at 19:17
  • I dont understand? I was supposed to create a class called segment, but needed the '*' to get the slope. – Justin Jul 18 '16 at 20:48

0 Answers0