Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

tcc8m

  • 3 years ago

Hi I have a question about Quiz 1 #5. Why do you need to insert the two lines at the bottom for the function to meet its specification? Check out my pastebin: http://pastebin.com/HJxRKWw0

  • This Question is Closed
  1. snark
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    the problem is that when you set result = v1 both result and v1 refer to the same address in memory - if you modify result, you also modify v1, but you are told not to modify the inputs. to avoid doing this, a copy of v1 and v2 is made: v1 = v1[:] v2 = v2[:] these are assigned new addresses in memory distinct from the v1 and v2 in the function call addVectors(v1,v2). (this would be clearer had he given them new names - w1 = v1[:] but maybe that's his point...)

  2. tcc8m
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks snark exactly what I was looking for.

  3. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy