Week 4 Excercise 10 Programming Assignment # 1

It has to do with the fact that objects are passed by reference in python. So if you use the “in place” operators like -=, you are actually modifying the global definitions of the arguments that are passed in, unless you take other action to create private copies. In other words, the two methods generate the same answer, but the way they manage memory is very different. Here’s a thread which discusses this in more detail. That thread discusses the case in Week 3, but the issue is the same here in Week 4. If the global values are passed in to more than one test, the subsequent tests all fail because the input values have been changed, unless you take action to avoid that side effect as described on that thread I linked.