自定义一个三维向量类,并实现向量之间的加法、减法,以及向量与标量之间的乘法与除法运算
class Vector:
def __init__(self,a,b,c):
self.x=a
self.y=b
self.z=c
def plus(self,m,n):
self.x=m.x+n.x
self.y=m.y+n.y
self.z=m.z+n.z
print((self.x,self.y,self.z))
def sub(self,m,n):
self.x=m.x-n.x
self.y=m.y-n.y
self.z=m.z-n.z
print((self.x,self.y,self.z))
def mul(self,m,i):
self.x=m.x*i
self.y=m.y*i
self.z=m.z*i
print((self.x,self.y,self.z))
def div(self,m,i):
self.x = m.x//i
self.y = m.y//i
self.z = m.z//i
print((self.x,self.y,self.z))
vector1=Vector(1,2,3)
vector2=Vector(2,4,6)
vector3=Vector(1,1,1)
vector3.plus(vector1,vector2)
vector3.sub(vector2,vector1)
vector3.mul(vector1,3)
vector3.div(vector2,2)