Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 16 Online
OpenStudy (anonymous):

If anyone has done PS7 (review problems), I can't figure out why the 5th program fails to swap s1 and s2 but the 7th program does reverse the list. Both functions manipulate the variables they are passed, but both return None. So it seemed to me neither should affect the variables passed to them when printed outside the function, or perhaps both should. But one does and the other doesn'. Any help would be much appreciated! Max @MIT 6.00 Intro Co…

OpenStudy (anonymous):

for 5) Remember that the local varibles s1 and s2 inside the swap0 function are different variables to the global s1 and s2, and that they are just pointers to lists rather than the lists themselves. the code inside the function just swaps the pointers that these variables contain, but does not change the list itself. Once the function returns these local variables no longer exist, and the global variables are unchanged, ie they still point to where they did originally for 7) the function is modifying the elements of the list and therefore the changes affect the whole program.

OpenStudy (anonymous):

Hey thanks a lot.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!