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