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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started