🐍 Can be run on Jupyter Notebook
#CLASS DESIGNED TO CREATE OBJECTS THAT TAKES COORDINATES AND CALCULATES DISTANCE AND SLOPE
class Line:def __init__(self,coor1,coor2):
self.coor1=coor1
self.coor2=coor2
#FUNCTION CALCULATES DISTANCE
def distance(self):return ((self.coor2[0]-self.coor1[0])**2+(self.coor2[1]-self.coor1[1])**2)**0.5
#FUNCTION CALCULATES SLOPE
def slope(self):return (self.coor2[1]-self.coor1[1])/(self.coor2[0]-self.coor1[0])
#DEFINING COORDINATES
coordinate1 = (3,2)coordinate2 = (8,10)
#CREATING OBJECT OF LINE CLASS
li = Line(coordinate1,coordinate2)
Comments
Post a Comment