Question: Write a function vector sum that has two arguments: vector1 and vector2 that are lists of numbers. If vector1 and vector2 have different lengths, the

Write a function vector sum that has two arguments: vector1 and vector2 that are lists of numbers. If vector1 and vector2 have different lengths, the function should return the null object None. Otherwise, the function should return a list of numbers that is equal to the sum of vector1 and vector2, considered as vectors.

So, vector sum([1,2,3], [4,5,6]) should return the list [5, 7, 9]. In general, if vector1 is the list [n0,n1,...,nk1] and vector2 is the list [m0, m1, . . . , mk1] then their sum, in this sense, is the list

[n0 +m0,n1 +m1,...,nk1 +mk1].

Your code should check to see if vector1 and vector2 have the same lengths. If not, then the function should return the null object None. This can be accomplished with the statement return None. Your code does not need to check that the arguments are lists of numbers. Do not confuse this vector addition with the python list extend method.

The code should be written in Python language.

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!