class Point: def _init_(self, p_x, P_y): self.x = P_x self.y - P_y def distance(self, P2): # Compute and return the distance between the # two points and return it def closer(self, P2, P3): # Return the point that is closer to this point def _str_(self): # Return a string representation of this point # according to the format: "(x,y)"

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

with python and should not contain import and test code

you will complete the following class which defines a simple 2-dimensional point and certain methods on it.
class Point:
def _init_(self, p_x, p_y):
self.x = P_x
self.y = p_y
def distance(self, P2):
# Compute and return the distance between the
# two points and return it
def closer(self, P2, P3):
# Return the point that is closer to this point
def _str_(self):
# Return a string representation of this point
# according to the format: "(x,y)"
You are already given the initializer for the class. Now, you have to complete the three methods: distance, closer and_str_. The distance method computes the
distance between this point and a point provided as argument to this method. It returns a float representing the distance. The closer method takes two other points and
returns the point object that is closer to this point. For example, p1.closer(p2,p3) returns p2, if p1 is closer to p2 compared to p3. Otherwise, it returns p3. Finally
str_returns a string representation of the point in the format (x,y).
Transcribed Image Text:you will complete the following class which defines a simple 2-dimensional point and certain methods on it. class Point: def _init_(self, p_x, p_y): self.x = P_x self.y = p_y def distance(self, P2): # Compute and return the distance between the # two points and return it def closer(self, P2, P3): # Return the point that is closer to this point def _str_(self): # Return a string representation of this point # according to the format: "(x,y)" You are already given the initializer for the class. Now, you have to complete the three methods: distance, closer and_str_. The distance method computes the distance between this point and a point provided as argument to this method. It returns a float representing the distance. The closer method takes two other points and returns the point object that is closer to this point. For example, p1.closer(p2,p3) returns p2, if p1 is closer to p2 compared to p3. Otherwise, it returns p3. Finally str_returns a string representation of the point in the format (x,y).
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY