Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write code in Python def __init__(self, vector): self.vector = vector #To compare and determine if both Vector objects are equal #Include this in your final

Write code in Python

image text in transcribed

def __init__(self, vector):

self.vector = vector

#To compare and determine if both Vector objects are equal

#Include this in your final submission

def __eq__(self, other):

return self.vector==other.vector

# --- Your code starts here

# --- ends here

[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 You must use the special methods for those three operators in order to override its 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 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.7 in https://docs.python.org/3/reference/datamodel.html [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 You must use the special methods for those three operators in order to override its 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 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.7 in https://docs.python.org/3/reference/datamodel.html

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions