Can Can someone explain to me how these both codes work | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
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

6th May 2020, 5:08 AM
Kashif Ali
Kashif Ali - avatar
4 Antworten
+ 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
6th May 2020, 5:15 AM
A͢J
A͢J - avatar
+ 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
6th May 2020, 5:23 AM
A͢J
A͢J - avatar
+ 2
Your first code. Print the value of i. But second code You print the value of j.
6th May 2020, 6:12 AM
Md Iftakher Hossain
Md Iftakher Hossain - avatar
0
But why the pattern is different? I mean the range in both codes is (1,5)
6th May 2020, 5:18 AM
Kashif Ali
Kashif Ali - avatar