Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON QUESTION Point2d.py file: import math class Point2d(object): def __init__( self, x0=0, y0=0 ): self.x = x0 self.y = y0 def magnitude(self): return math.sqrt(self.x**2 +

PYTHON QUESTION

Point2d.py file:

import math

class Point2d(object): def __init__( self, x0=0, y0=0 ): self.x = x0 self.y = y0

def magnitude(self): return math.sqrt(self.x**2 + self.y**2)

def dist(self, o): return math.sqrt( (self.x-o.x)**2 + (self.y-o.y)**2 ) if __name__ == "__main__": p = Point2d(0,4) q = Point2d(5,10) leng = q.magnitude() leng = Point2d.magnitude(q) print("Magnitude {:.2f}".format( leng )) print("Distance is {:.2f}".format( p.dist(q) ))

Write a new Point2d method called scale that takes as an input argument a Point2dobject (self) and a numerical value (int or float) and multiples both the x and yattributes by this value.

Write a new Point2d method called dominates that two takes two Point2d objects and returns True if and only if the x coordinate of the first object is greater than that of the second object and the y coordinate of the first object is greater than that of the second object.

The code to test these functions is commented out in the main code area. Please remove this commenting, test your code, and submit your resulting Point2d.py file. Call it Point2d_q1.py

Copy your resulting file from the first question to a new file, perhaps called Point2d_q2.py.

Write and test the implementation of the method __str__ which returns a string created from the values of a Point2d object. For our purposes this is mostly used to create a string that can be printed. Make sure you have this working before you proceed to the other parts of this exercise because they depend on it.

Write the implementation of the subtraction method __sub__ for the Point2d object. Uncomment the code in the main area and test this in Wing IDE.

Write the implementation of the method __mul__ which is like the scale function you wrote for part 1, but it creates a new Point2d object.

Write the implementation of the method __eq__ which returns True if and only if the two Point2d objects have exactly the same x and y values.

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

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago