设计一个三维向量类,并实现向量的加法,减法以及向量与标量的乘法和除法运算

class Vecter3:
    def_init_(self,x=0,y=0,z=0):
              self.X=x
              self.Y=y
              self.Z=z
    def_add_(self,n):
              r=Vecter3()
              r.X=self.X+n.X
              r.Y=self.Y+n.Y
              r.Z=self.Z+n.Z
              return r
    def_sub_(self,n):
              r=Vecter3()
              r.X=self.X-n.X
              r.Y=self.Y-n.Y
              r.Z=self.Z-n.Z
              return r
    def_mul_(self,n):
              r=Vecter3()
              r.X=self.X*n
              r.Y=self.Y*n
              r.Z=self.Z*n
              return r
    def_truediv_(self,n):
              r=Vecter3()
              r.X=self.X/n
              r.Y=self.Y/n
              r.Z=self.Z/n
              return r
    def_floordiv_(self,n):
              r=Vecter3()
              r.X=self.X//n
              r.Y=self.Y//n
              r.Z=self.Z//n
              return r
    def show(self):
              print(self.X,self.Y,self.Z))

  

文章来自:https://www.cnblogs.com/leeing/p/12742219.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3