0
Can Can someone explain to me how these both codes work
Can someone explain to me how these both codes work for i in range(1,5): for j in range (1,5): print (i, end ='') print () Result= 1111 2222 3333 4444 And If we just replace i with j for i in range(1,5): for j in range (1,5): print (j, end ='') print () Result= 1234 1234 1234 1234
4 Answers
+ 3
Kashif Ali
In the first code we are printing the value of i inside another loop so
For i = 1, i will print 4 times 1111
For i = 2, i will print 4 times 2222
-----------------
For i = 4, i will print 4444
In the second Code we are printing the value of j so
for i = 1, j will print 1234
for i = 2, j will print again 1234
---------------
for j = 4, j will print 1234
+ 3
Kashif Ali yes range is same but for the Every iteration of first loop, inside loop will print value from range 1 to 5 so in the second Code every time j will change and print the value like 1234
But in the first code inside second loop every time i will be same and print the value like 1111
+ 2
Your first code.
Print the value of i.
But second code
You print the value of j.
0
But why the pattern is different? I mean the range in both codes is (1,5)