Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 8th, 2012  |  syntax: Python  |  size: 0.61 KB  |  views: 51  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.
clone this paste RAW Paste Data