1、设计一个向量类,实现数据的输入、输出、向量的加法、减法、点积、夹角等计算:
#1,设计一个向量类,
# 实现数据的输入、输出、向量的加法、减法、点积、夹角等计算
import math
class vecter:
def __init__(self,x=1,y=1):
if( x==1 and y==1 ):
self.x, self.y = (map(int, input("请输入向量 (x1,y1)->(x2,y2)").split()))
self.x=x
self.y=y
def printf(self):
print("x = " ,self.x," y = ",self.y )
def __add__(self, other):
t=vecter(0,0)
t.x = self.x + other.x
t.y = self.y + other.y
return t
def __sub__(self, other):
t = vecter(0, 0)
t.x = self.x - other.x
t.y = self.y - other.y
return t
def dot(self,other):
t=self.x*other.x+self.y*other.y
return t
def Mod(self):
return math.sqrt(self.x*self.x+self.y*self.y)
def angle(