The following code computes the distance and the slope between two coordinates. The tuple unpacking is perform directly in the functions .distance() and .slope(). I would like to perform the tuple unpacking directly in the __init__method. Do you have any idea how to do it? I tried with indexing but probably I did something wrong.
class Line(): #We define the variables (attributes of the class) def __init__(self,coor1,coor2): self.coor1=coor1 self.coor2=coor2 #We define a function that unpack the tuples and calculates the distance between the points def distance(self): x1,y1=self.coor1 x2,y2=self.coor2 return ((x2-x1)**2+(y2-y1)**2)**(1/2) #We define a function that unpack the tuples and calculate the slope def slope(self): x1,y1=self.coor1 x2,y2=self.coor2 return (y2-y1)/(x2-x1)