Resolved: Questions about the transformation function
On the line:
a,b = trans((a,b))
I understand that the p becomes (a,b), but what happens next?
Ler's say we take
trans_3. Can someone explains what happens inside the function when we call
Thank you for your question!
Let me suggest a modification to the code, where I have included 3
Then, let's study the
for-loop on lines 31-35, where I have reduced the number of iterations to 3.
On line 32, we assign the variable
trans one of the 3 functions -
trans_3. From the output, we can see that the choice during the first iteration was
trans_3. On line 33, we modify the integers
b using the function
trans_3. What happens in this function is the following:
1. The variable
p represents the tuple
2. Line 18 -
x equals the first item in
3. Line 19 -
y equals the second item in
4. Line 20 -
x1 is computed according to Transformation 3, using variable
5. Line 21 -
y1 is computed according to Transformation 3, using variable
6. Line 23 - the function returns the variables
y1 in a tuple
Going back to line 33, variable
a is assigned the value
x1 while variable
b is assigned the value
y1. These are then appended to the lists
Then, the second iteration comes, where, this time, the function
trans_1 is chosen. The whole procedure from above repeats.
trans_3 is chosen again during the third iteration.
Hope this helps!