Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The second picture are all of the required tests that need to be passed. Goal: [10pts] Write the class Vector that supports the basic vector
The second picture are all of the required tests that need to be passed.
Goal: [10pts] Write the class Vector that supports the basic vector operations. Such operations are addition (+) and subtraction (-) of vectors of the same length, dot product (*) and multiplication (*) of a vector by a scalar. All methods must return (not print) the result. Your class should also support the rich comparison for equality You must use the special methods for those 4 operators in order to override their behavior You will need other special methods to achieve a legible object representation. Dot product and multiplication by scalar use the same operator, so you must check the type of the object in order to decide which operation you have to perform For addition and subtraction, you must check that vectors have the same length The dot product results in a scalar, not a Vector The rest of the methods must return a Vector obiect (not a string with the word Vector) - - - - - - Test your code, this is how you ensure you get the most credit out of your work!! - When returning error messages, make sure your string contains the word 'error Check the doctest for object behavior examples. Vector size is variable Hint: Section 3.3.8. Emulating numeric types in - docs. python.org/3 reference datamodellt ml #emulating-numeric-tves class Vector: >>> Vector ([1,2]) +Vector (15]) Error Invalid dimensions' >>> Vector ([1,2]) +Vector ([5,2]) Vector([6, 41 >>>Vector (11,2])-Vector ([5,21) Vector (I-4, 01) > Vector ([1,2]) Vector ([5,2]) >>>x-Vector (12,4,6]) >>> y-Vector (12,4,6]) >>> c=x+y >>> type (c)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started