Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

class Point: def __init__ (self, x = 0, y = 0): self.__x = x self.__y = y def get_x(self): return self.__x def get_y(self): return self.__y

image text in transcribed

class Point: def __init__ (self, x = 0, y = 0): self.__x = x self.__y = y def get_x(self): return self.__x

def get_y(self): return self.__y def move(self,dx,dy): self.__x += dx self.__y += dy return dx, dy def move_to(self, newx, newy): self.__x = newx self.__y = newy return newx, newy def __str__(self): return '(' + str(self.__x) + ', ' + str(self.__y) + ')' def __repr__(self): return 'Point' + '({0}, {1})'.format(self.__x, self.__y) def distance(self,p): return def isNearby(p): return

Now, you will again add a few methods to your Point class to extend its functionality. Starting with your solution to the previous task, now add: . A method named distance(p) which takes another Point object as a parameter and returns the distance to that point. . A method called isNearBy (p) that returns true if the point p is close to this point. Two points are close if their distance is less than 5 Note: you must submit the entire class definition. Note - keep a copy of your solution to this task because you will be extending it step by step in subsequent tasks. For example: Test Result p Point (10,20) r Point (30,40) print("%.2f" % p,distance(r)) 28.28

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

Step: 3

blur-text-image

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

Sybase Database Administrators Handbook

Authors: Brian Hitchcock

1st Edition

0133574776, 978-0133574777

More Books

Students also viewed these Databases questions