Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Vector:
- def __init__(self, x, y):
- self.x = x
- self.y = y
- def __str__(self): # строчное представление
- return "Vector({},{})".format(self.x, self.y)
- def __add__(self, other): # +
- return Vector(self.x + other.x, self.y + other.y)
- def __iadd__(self, other): # +=
- self.x += other.x
- self.y += other.y
- def __mul__(self, other): # *
- if isinstance(other, (int, float)):
- return Vector(self.x * other, self.y * other)
- if isinstance(other, Vector):
- return self.x * other.x + self.y * other.y
- else:
- raise TypeError("неправильный тип")
- def __imul__(self, other):
- if isinstance(other, (int, float)):
- self.x *= other
- self.y *= other
- else:
- raise TypeError("lol")
- def __sub__(self, other): # -
- if isinstance(other, Vector):
- return Vector(self.x - other.x, self.y - other.y)
- def __isub__(self, other): # -=
- if isinstance(other, Vector):
- self.x -= other.x
- self.y -= other.y
- class Point:
- def __init__(self, x, y):
- self.x = x
- self.y = y
- def __str__(self):
- return "Point({},{})".format(self.x, self.y)
- '''
- a = Vector(3,2)
- b = Vector(1,1)
- p1 = Point(1,1)
- print(a + b)
- print(randint(1,10))
- '''
- help(isinstance)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement