Question: using python 3: implement the distFrom method. class Point: def __init__(self, initX, initY): Create a new point at the given coordinates self.__x =

using python 3: implement the distFrom method.

class Point:

def __init__(self, initX, initY): """ Create a new point at the given coordinates """ self.__x = initX self.__y = initY

def getX(self): """ Get its x coordinate """ return self.__x

def getY(self): """ Get its y coordinate """ return self.__y

def __str__(self): """ Return a string representation of the point """ return "({}, {})".format(self.__x, self.__y)

def halfway(self, other): """ Create a point halfway between self and other """ mx = (self.__x + other.__x) / 2 my = (self.__y + other.__y) / 2 return Point(mx, my)

def distFromOrigin(self): """ Return the distance from self to (0,0) """ return (self.__x**2 + self.__y**2)**0.5

def distFrom(self, other): """ Return the distance from self to other """ return 0

if __name__ == "__main__": import test import unittest class TestPoint(unittest.TestCase): def setUp(self): pass

def test_distFrom_1(self): p = Point(1, 0) self.assertEqual(p.distFrom(Point(4, 0)), 3)

def test_distFrom_2(self): p = Point(0, 0) self.assertEqual(p.distFrom(Point(1, 0)), 1)

unittest.main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!