-
2/14/23
-
Before changing anything, check out a new branch in which to work.
-
Write an
__init__method forVector2dthat has positional parameters for thexandycomponents that correspond to the instance variablesself.xandself.y -
Write a
__repr__method for theVector2dclass. A good general rule forrepris that it should produce a string similar to the code used to create the object it describes. For example,repr(Vector2d(3,4))could produce'Vector2d(x=3, y=4)'. -
Write a
__str__method for theVector2dclass such thatstr(Vector2d(3, 4))would return'3i + 4j'. (i and j are what many physicists and engineers use to denote the x and y directions) -
Write an
__abs__function that takesselfas its only argument and returns the length of the hypotenuse of the right triangle with legs equal toself.xandself.y. For example,abs(Vector2d(3, 4))should return5.0. -
Once you've finished today's work, commit your changes and push them to your repository.
-
-
2/16/23
-
The
__neg__method determines the behavior of the unary minus (leading minus sign) on aVector2dobject.Write a__neg__method that takesselfas its only argument and returns aVector2dobject with the signs forxandynegated. For example,-Vector2d(3, 4)would returnVector2d(-3, -4). -
The
__add__method determines how the '+' symbol works between twoVector2dobjects. Write an__add__method that has two arguments,selfandother, and produces aVector2dobject with the correct components. Remember that when we add vectors, we simply add their like components. For example:Vector2d(3, 4) + Vector2d(1, -1)should returnVector2d(4, 3), since3 + 1 = 4and4 + -1 = 3. -
Once you've finished the day's work, commit your changes and push them to your repository.
-