level: initial
In the following code, my 'same point' function returns incorrectly, where I find the truth Is expected. Any signals?
import math class cPoint: def __init __ (self, x, y): self.x = x self.y = y self.radius = math.sqrt (self.x * Self. X + self.y * self.y) self.angle = math.atan2 (self.y, self.x) def cartesian (self): return (self. X, self.) DEF polar (self): return (self .Radios, Self Angles) Class P Point: Def __int __ (Self, R, A): Self. RDI = R itself Angle = One self X = R * Math Kos (A) Self. Y = R * Math.sin (a) def cartesian (self): return (self. X, self.) DEF polar (self): returns (own radii, self.), Def only one (P, Q) : Returns (p. Cartesian == q.cartesian) & gt; & Gt; & Gt; P = cPoint (1.0000000000000000002, 2.0) & gt; & Gt; & Gt; Q = pPoint (2.23606797749979, 1.1071487177940904) & gt; & Gt; & Gt; P.cartesian () (1.0000000000000000002, 2.0) & gt; & Gt; & Gt; Q.cartesian () (1.000000000000000000002, 2.0) & gt; & Gt; & Gt; Same point (p, q) false & gt; & Gt; & Gt; Source: MIT OpenCarswerware Computer Science and Programming Introduction 2008 2008
< P> Seeing your code def same point (p, q): returns (pcartisian == q.cartesian)
p.cartesian, Q .cartesian function and you're comparing the function instead of the result. Since comparing two specific actions, the result is false
Should you have coding
def same page (p, q): return (p cutision ) == q.cartesian ())
Comments
Post a Comment