Can you please explain me the whole process of the output? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

Can you please explain me the whole process of the output?

num=[1,3,5,6] for i in num: for c in range (i): print (c)

14th May 2020, 8:23 PM
Bhanu Tripathi
Bhanu Tripathi - avatar
1 Réponse
+ 1
for i in num : #list value are taken into i in each iteration one after other, so for first iteration, i = 1, next 3, next 5, next 6 Inner loop i=1 for c in range(i) : #means 0 to i-1 times iterates, I not inclusive. So c=0 to i-1=0 Print 0 i=3: c= 0 to 3-1=2 prints 0, 1, 2 #separelate lines. i=5 c=0 to 5-1=4 Prints 0,1,2,3,4 i=6 c=0 to 6-1= 5 Prints 0,1,2,3,4,5 Output: #each value printed in separate lines but for your convenience, final output: 0 0 1 2 0 1 2 3 4 0 1 2 3 4 5
14th May 2020, 8:38 PM
Jayakrishna 🇮🇳