您的位置:首页 > 汽车 > 新车 > 《python语言程序设计》2018版第8章17题point类设计一个名为point的类

《python语言程序设计》2018版第8章17题point类设计一个名为point的类

2025/6/20 22:10:35 来源:https://blog.csdn.net/m0_37228426/article/details/142137103  浏览:    关键词:《python语言程序设计》2018版第8章17题point类设计一个名为point的类

在这里插入图片描述
TypeError: point_class.dis_m() missing 1 required positional argument: ‘y2’

请添加图片描述

这段代码为什么出错请添加图片描述

一个又一个错误
请添加图片描述

请添加图片描述

终于摸到点头绪

请添加图片描述

#distance方法 我做的叫get_dis_m

def get_dis_m(self):a_m = self.__x1 - self.__x2b_m = self.__y1 - self.__y2return (pow(a_m, 2) + pow(b_m, 2)) ** 0.5x_1, y_1, x_2, y_2 = 2.1, 2.3, 19.1, 19.2
a1=point_class(x_1, y_1, x_2, y_2).get_dis_m()
print(a1)

经过对第8章的复习,我做出了下面的代码

class point_class:def __init__(self, x1, y1, x2, y2):self.__x1 = x1self.__y1 = y1self.__x2 = x2self.__y2 = y2def set_x1(self, x1):self.__x1 = x1def set_y1(self, y1):self.__y1 = y1def set_x2(self, x2):self.__x2 = x2def set_y2(self, y2):self.__y2 = y2def get_cr_point(self, x1, y1):self.__x1 = 0self.__y1 = 0return turtle.goto(x1, y1)def get_dis_m(self):a_m = self.__x1 - self.__x2b_m = self.__y1 - self.__y2return (pow(a_m, 2) + pow(b_m, 2)) ** 0.5def is_near_by(self):a = point_class(self.__x1, self.__y1, self.__x2, self.__y2)if a.get_dis_m() <= 5:print("The two points area near each other")else:print("The two points area not near each other")def __str__(self):return x_1, y_1x_1, y_1, x_2, y_2 = 2.1, 2.3, 19.1, 19.2
a1 = point_class(x_1, y_1, x_2, y_2).get_dis_m()
point_class(x_1, y_1, x_2, y_2).is_near_by()
a2 = point_class(x_1, y_1, x_2, y_2).__str__()
print(a1)
print("str",type(a2),"is",a2)

请添加图片描述

end

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com