From b2ada8eb18dfdac600dd7c8787d43f980e6a5c3c Mon Sep 17 00:00:00 2001 From: MariaKAP1 <121195659+MariaKAP1@users.noreply.github.com> Date: Wed, 22 Feb 2023 20:07:48 +0000 Subject: [PATCH] created different methods and follow 2/22 instructions --- main.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 104be10..c11e053 100644 --- a/main.py +++ b/main.py @@ -1,2 +1,25 @@ class Vector2d: - pass \ No newline at end of file + def __init__(self, x, y): + self.x = x + self.y = y + + def __repr__(self): + return f"Vector2d(x ={self.x},y= {self.y})" + + def __str__(self): + return f"{self.x}i + {self.y}j" + + def __abs__(self): + return (self.x** 2 + self.y**2)**.5 + + def __neg__(self): + return (-self.x, -self.y) + + def __add__(self,other): + return Vector2d(self.x + other.x, self.y + other.y) + + def __eq__(self,other): + return (self.x, self.y) == (other.x, other.y) + + def __sub__(self,other): + return Vector2d(self.x - other.x,self.y - other.y) \ No newline at end of file