0

Can anyone explain this nested loop?

n=3 for i in range(1,n+1): for j in range(1,i): print("#",end=" ") print( )

24th Jan 2021, 10:25 AM
Prithika
6 odpowiedzi
+ 3
Change "#" to j and set n to 4 or 5. Also put the last print in the outer loop. Then you can understand it from the output I guess. n=5 for i in range(1, n+1): for j in range(1, i): print(j, end=" ") print()
24th Jan 2021, 10:48 AM
Benjamin Jürgens
Benjamin Jürgens - avatar
0
Thank u benjamin I want the output of the program to be like this * * * * * * How to code the program thru nested for loop to get the above output?
24th Jan 2021, 11:59 AM
Prithika
0
Thanks Kiboo What will happen if i go with i instead of n in inner for loop n=3 for i in range(1,n+1): for j in range(1,i): print("#",end=" ") print( )
24th Jan 2021, 12:58 PM
Prithika
0
Mr.kiboo can u explain how nested loop works? Please
24th Jan 2021, 1:20 PM
Prithika