diff --git a/instructions.md b/instructions.md index e1ed429..6b0db7b 100644 --- a/instructions.md +++ b/instructions.md @@ -31,4 +31,4 @@ - 2/23/23 - - Write a method called `angle` that has `self` as its only parameter and returns the arctangent **in degrees** of the vector's `y` and `x` components. **NOTE:** You'll want to consult the documentation for [`math.atan2(y, x)`](https://docs.python.org/3/library/math.html#math.atan2) and [`math.degrees(x)`](https://docs.python.org/3/library/math.html#math.degrees) \ No newline at end of file + - Write a method called `angle` that has `self` as its only parameter and returns the arctangent **in degrees** of the vector's `y` and `x` components. **NOTE:** You'll want to consult the documentation for [`math.atan2(y, x)`](https://docs.python.org/3/library/math.html#math.atan2) and [`math.degrees(x)`](https://docs.python.org/3/library/math.html#math.degrees) diff --git a/main.py b/main.py index 104be10..6918e09 100644 --- a/main.py +++ b/main.py @@ -1,2 +1,18 @@ +import math class Vector2d: - pass \ No newline at end of file + def __init__(self,x,y): + self.x,self.y = x,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 f"Vector2d(-{self.x},-{self.y})" + def __add__(self,other): + return f"Vector2d{self.x + other.x},{self.y + other.y}" + def __eg__(self,other): + return self.x == other.x and self.y and other.y + def angle(self): + return math.degrees(math.atan2(self.y,self.x)) \ No newline at end of file