Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Vi Special Issue On Database And Expert Systems Applications Lncs 7600

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2012th Edition

3642341780, 978-3642341786

More Books

Students also viewed these Databases questions

Question

7. Identify six intercultural communication dialectics.

Answered: 1 week ago