Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

The second picture are all of the required tests that need to be passed.

image text in transcribed

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) >>> print (c) Vector (14, 8, 12]) True >>> x-Vector (1,2]) Error Invalid dimensions' 'Error Invalid operation' x x*y 56 > x*5 Vector ([10, 20, 30]) Vector (I10, 20, 30]) -init-(self, vector-list): self.vector vector list def You r code starts here

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

Database And Expert Systems Applications 19th International Conference Dexa 2008 Turin Italy September 2008 Proceedings Lncs 5181

Authors: Sourav S. Bhowmick ,Josef Kung ,Roland Wagner

2008th Edition

3540856536, 978-3540856535

More Books

Students also viewed these Databases questions

Question

2. Describe how technology can impact intercultural interaction.

Answered: 1 week ago

Question

7. Define cultural space.

Answered: 1 week ago