Making a Point Class in Python

前端 未结 4 1979
旧时难觅i
旧时难觅i 2020-12-17 05:28

I am trying to create a class in python titled \"Point.\" I am trying to create a point on a coordinate plane x and y and track them. As well as find the distance between th

4条回答
  •  失恋的感觉
    2020-12-17 06:24

    Don't forget math.hypot

    def distance(self, p):
        dx = self.X - p.X
        dy = self.Y - p.Y
        return hypot(dx, dy)
    

提交回复
热议问题