Question: Python REALLY NEED HELP !!!!!!!!! [10pts] Write the class Vector that supports the basic vector operations. Such operations are addition (+) and subtraction (-) of

Python REALLY NEED HELP !!!!!!!!!

[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 object (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

    https://docs.python.org/3/reference/datamodel.html#emulating-numeric-types

    Deliverables:

class Vector:

'''

>>> Vector([1,2])+Vector([5])

'Error - Invalid dimensions'

>>> Vector([1,2])+Vector([5,2])

Vector([6, 4])

>>> Vector([1,2])-Vector([5,2])

Vector([-4, 0])

>>> Vector([1,2])*Vector([5,2])

9

>>> x=Vector([2,4,6])

>>> y=Vector([2,4,6])

>>> c=x+y

>>> type(c)

>>> print(c)

Vector([4, 8, 12])

>>> x==y

True

>>> x-Vector([1,2])

'Error - Invalid dimensions'

>>> x+5

'Error - Invalid operation'

>>> x*y

56

>>> x*5

Vector([10, 20, 30])

>>> 5*x

Vector([10, 20, 30])

'''

def __init__(self, vector_list):

self.vector = vector_list

# --- Your code starts here

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!