- 1
can you tell how it works please
T = [[3-i for i in range (3)] for j in range (3)] s = 0 for i in range(3): s += T[i][i] print(s) (output = 6) can you explain
5 odpowiedzi
+ 1
s sums up the numbers in T[i][i].
On the first iteration of the loop, s will become s = s + T[0][0], which is s = s + 3 when we look at T.
On the next iteration, we will add the next number to s and s will be s = s + T[1][1] and so forth
+ 1
Great you could solve it!
0
You asked the same question yesterday and I recommended you to put the code in a script on sololearn playground and print out the steps.
Print T and print i and s and T[i][i] on each iteration.
0
Thank you for answering my questions
I did understand how to find i and T but I did not understand how to find s I tried the way you said, but I still not understanding.
0
okay I got it thank you again!