Jul-31-2021, 11:17 AM
Hi,
I read a book with this below question and answer.
However I cant get the meaning of the explanation.
First loop are 1,1 ; 1,2 ; 1,3.
Second loop are 2,1 ; 2,2.
Third loop are 3,1.
Fourth loop is nothing.
>>> So x = 2 + 3 + 4 + 3 + 4 + 4 = 20
Why there is nothing in the fourth loop?
How is the logic of this loop ?
I read a book with this below question and answer.
However I cant get the meaning of the explanation.
x = 0 n = 5 for i in range(1, n): for j in range(1, n): if((i+j) == 2): x = x + 2 if((i+j) == 3): x = x + 3 if((i+j) == 4): x = x + 4 print(x)
Output:20
The explanation was: First loop are 1,1 ; 1,2 ; 1,3.
Second loop are 2,1 ; 2,2.
Third loop are 3,1.
Fourth loop is nothing.
>>> So x = 2 + 3 + 4 + 3 + 4 + 4 = 20
Why there is nothing in the fourth loop?

How is the logic of this loop ?
