instances of the class Point
do not have an attribute center
, in these three lines of code you assume they do:
if isinstance(check,(Point)):
if math.sqrt(((Point.x_val(self.center))-(Point.x_val(check.center)))**2 + ((Point.y_val(check.center))-(Point.y_val(check.center)))**2) <= self.radius:
return True
If check
is an instance of Point
don't refer to check.center
.
BTW, please give the full stack trace when asking questions like these, not just the last line. With the full trace I could have just looked at the line with the error instead of having to look through the rest of the code.
What you probably wanted was just to access the x value of the Circle's center and the x of the check Point.
if isinstance(check,(Point)):
if math.sqrt((self.center.x-check.x)**2 + (self.center.y-check.y)**2) <= self.radius:
return True
Note that using a method to access an attribute is considered not to be good style in Python. If you want to access the value of an attribute just access the attribute directly. In some languages this can problems if later you need to change how an object is implemented but in Python you can change an attribute into a property at any time without breaking code.