相关疑难解决方法(0)

在Python中创建一个Point类

我正在尝试在python中创建一个名为"Point"的类.我试图在坐标平面x和y上创建一个点并跟踪它们.以及找到点之间的距离.我必须使用函数和方法.我已经开始了,这是我的代码.我执行程序时,我只是不确定如何使用它.任何帮助将不胜感激.

编辑:更新的代码

import math


class Point(object):
    '''Creates a point on a coordinate plane with values x and y.'''

    COUNT = 0

    def __init__(self, x, y):
        '''Defines x and y variables'''
        self.X = x
        self.Y = y

    def move(self, dx, dy):
        '''Determines where x and y move'''
        self.X = self.X + dx
        self.Y = self.Y + dy

    def __str__(self):
        return "Point(%s,%s)"%(self.X, self.Y) 


    def getX(self):
        return self.X

    def getY(self):
        return self.Y

    def distance(self, other):
        dx = self.X - other.X
        dy = self.Y …
Run Code Online (Sandbox Code Playgroud)

python methods class function point

2
推荐指数
2
解决办法
4万
查看次数

标签 统计

class ×1

function ×1

methods ×1

point ×1

python ×1