I have a problem with the last operation///TypeError: unsupported operand type(s) for /: 'Vector' and 'int'

27 views Asked by At

CODE:

class Vector(object):
    def __init__(self,x,y):
        self.x=x
        self.y=y
    def __add__(self,v):
        return Vector(self.x + v.x,self.y + v.y)
    def __sub__(self,v):
        return Vector(self.x - v.x,self.y - v.y)
    def __mul__(self,s):
        return Vector(self.x * s,self.y * s)
    def __div__(self,s):
        s_float = float(s)
        return Vector(self.x / s_float,self.y / s_float)
    def __floordiv__(self,s):
        return Vector(self.x // s,self.y // s)
    def __repr__(self):
        return '<Vector(%f,%f)>'%(self.x,self.y,)

a = Vector(3,5)

b = Vector(2,7)




print(a+b)

print(b-a)

print(b*1.3)

print(a//17)

print(a / 17) #this is the operation that is not performed

TypeError: unsupported operand type(s) for /: 'Vector' and 'int'

0

There are 0 answers