From 5ad7f7db6be2ab79fed312e85e92ae21adda2241 Mon Sep 17 00:00:00 2001 From: namseybandz <121195708+namseybandz@users.noreply.github.com> Date: Fri, 24 Feb 2023 19:40:29 +0000 Subject: [PATCH] Vector2d class updated --- main.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 104be10..2b09574 100644 --- a/main.py +++ b/main.py @@ -1,2 +1,20 @@ class Vector2d: - pass \ No newline at end of file + def __init__(self,x,y): + self.x = x + self.y = y + def __repr__(self): + return "Vector2d(x = {self.x}, y = {self.y})" + def __str__(self): + return "(self.x)i + {self.y}j" + def __abs__(self): + return h (((self.x**2) + (self.y**2))**1/2) + def __neg__(self): + return Vector2d(self.x*-1, self.y*-1) + def __add__(self , other): + return Vector2d((self.x + other.x, 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) + return hypot +