0
List Question
I am trying to find the values of the elements in list a1 after the following code executes: def mystery1(a1, a2): for i in range(len(a1)): a1[i] += a2[len(a2) - i - 1] a1 = [1, 3, 5, 7, 9] a2 = [1, 4, 9, 16, 25] mystery1(a1, a2) I'm a little lost as to what the values would be with the calls a1[0], a1[1], a1[2], a1[3], a1[4]...
1 Answer
+ 2
First of all, I recommend ârunning the codeâ on paper and just going through the steps, with the value of i and seeing what it will be.
Secondly, a1[0] = a2[5-0-1)= a2[4] = 25
a1[1] = a2[5-1-1] = a2[3] = 16
And then just keep going backwards through the values of a2