.定义一个坐标点的类,数据成员有坐标×,坐标y。/函数成员:置坐标点,打印坐标点,求坐标点的*轴对称和y轴对称。//在主函数中,输入一个点,打印出关干轴的对称点和关于轴的对称点:
时间: 2024-06-02 13:14:27 浏览: 102
class CoordinatePoint:
def __init__(self, x=0, y=0):
self.x = x
self.y = y
def set_coordinate(self, x, y):
self.x = x
self.y = y
def print_coordinate(self):
print("({},{})".format(self.x, self.y))
def x_axis_symmetric_point(self):
return CoordinatePoint(self.x, -self.y)
def y_axis_symmetric_point(self):
return CoordinatePoint(-self.x, self.y)
if __name__ == "__main__":
x = int(input("请输入x坐标:"))
y = int(input("请输入y坐标:"))
point = CoordinatePoint(x, y)
print("输入的坐标点为:", end="")
point.print_coordinate()
print("关于x轴对称的点为:", end="")
point.x_axis_symmetric_point().print_coordinate()
print("关于y轴对称的点为:", end="")
point.y_axis_symmetric_point().print_coordinate()
阅读全文