Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Import math class Point 2 D: def _ _ init _ _ ( self , x , y ) : self.x = x self.y =
Import math
class PointD:
def initself x y:
self.x x
self.y y
class Line:
def initself point point:
self.p point
self.p point
pass
@property
def getDistanceself:
return roundmathsqrtpowselfpx self.px powselfpy self.py
pass
@property
def getSlopeself:
if self.px self.px :
return math.inf
return roundselfpy self.pyselfpx self.px
pass
def strself:
if self.px self.px :
return "Undefined"
elif self.getSlope :
return fy roundselfpy self.getSlope self.px
return fy selfgetSlopex roundselfpy self.getSlopeselfpx
reprstr
def mulselfother:
# YOUR CODE CONTINUES HERE
def containsselfpoint:
# YOUR CODE CONTINUES HERE
mul
A special method to support the operator. Returns a new Line object where the xy attributes of every PointD object is multiplied by an integer. The only operation allowed is Lineinteger any other noninteger values return None.
contains
A special method to support the in operator. Returns True if the Point object lies on the Line object, False otherwise. You cannot make any assumptions about the value that will be on the right side of the operator. If the slope is undefined, return False.
Recall that floatingpoint numbers are stored in binary, as a result, the binary number may not accurately represent the original base number. For example:
False
This error, known as floatingpoint representation error, happens way more often than you might realize. To implement this method, you will need to compare floatingpoint numbers. Avoid checking for equality using with floats. Instead use the isclose method available in the math module:
import math
math.isclose
True
math.isclose checks if the first argument is acceptably close to the second argument by examining the distance between the first argument and the second argument, which is equivalent to the absolute value of the difference of the values:
x
y
absxy
e
If absx y is smaller than some percentage of the larger of x or y then x is considered sufficiently close to y to be "equal" to y This percentage is called relative tolerance.
Examples:
p PointD
p PointD
line Linep p
line line
isinstanceline Line
True line y x
line line
line
y x
lineLinePointDPointD
line
y x
PointD in line
False
PointD in line
True
in line
False
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