Advertisement
Guest User

Untitled

a guest
Dec 8th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. 5) The following code does not meet its specification. Correct it. (8 points)
  2.  
  3. def addVectors(v1, v2):
  4. """assumes v1 and v2 are lists of ints.
  5. Returns a list containing the pointwise sum of the elements in v1 and v2. For example, addVectors([4,5], [1,2,3]) returns [5,7,3],and addVectors([], []) returns []. Does not modify inputs."""
  6.     if len(v1) > len(v2):
  7.         result = v1
  8.         other = v2
  9.     else:
  10.         result = v2
  11.         other = v1
  12.     for i in range(len(other)):
  13.         result[i] += other[i] return result
  14.  
  15. # Here is the answer to the question
  16.  
  17. insert the lines
  18. v1 = v1[:] v2 = v2[:]
  19. before the first line of executable code.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement