- 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

12th Apr 2022, 5:36 AM
Lin
5 ответов
+ 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
12th Apr 2022, 6:56 AM
Lisa
Lisa - avatar
+ 1
Great you could solve it!
12th Apr 2022, 7:01 AM
Lisa
Lisa - avatar
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.
12th Apr 2022, 6:35 AM
Lisa
Lisa - avatar
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.
12th Apr 2022, 6:53 AM
Lin
0
okay I got it thank you again!
12th Apr 2022, 7:01 AM
Lin