Question:
The purpose is to calculate the average value (AverageU) from a starting array (StartingU)
The for loops that calculate the average values for AverageU
Output:
The problem is why StartingU gets updated? It should be unchanged
Answer:
AverageU changed since this code, not after for loop.
AverageU and StartingU are the same instances. You can check it with is function.
You should make a new instance as the comment said.
AverageU = StartingU This code just makes another reference to the same object with a new name and this indicates the same memory. You can check the memory address of the variable with function
id
You can compare like this.
Notice
Copy with the colon is actually a shallow copy, it copies only the reference of the nested list.
If you have better answer, please add a comment about this, thank you!