I'm still new to this site, so forgive poor formatting. I'm trying to make a class for a point on a cartesian plane and a method for finding the slope of a line when given two points. However, while working on it, pycharm tells me that Instance attribute slope(name of variable) defined outside __init__. However when I place self.slope into __init__ and assign it to run it gives the following error:
Traceback (most recent call last):
File "/Volumes/SEAGATE_for_editing/Programming/Python/graphing stuff/stuff.py", line 28, in <module>
print(point1.slope(point2))
TypeError: 'NoneType' object is not callable
How do I fix this? Here is my code. Any help is greatly appreciated.
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
self.y_slope = None
self.x_slope = None
self.slope = None
def slope(self, other):
self.y_slope = other.y - self.y
self.x_slope = other.x - self.x
self.slope = self.y_slope / self.x_slope
return self.slope
def dist(self, other):
self.x_dist = other.x - self.x
self.y_dist = other.y - self.y
self.distance = ((self.x_dist ** 2) + (self.y_dist ** 2)) ** (1/2)
return self.distance
point1 = Point(-2, -5)
point2 = Point(1, 1)
print(point1.slope(point2))
print(round(point1.dist(point2), 4))