Nested loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Nested loop

n=int(input("enter the number of rows:")) for i in range (1,n+1): for j in range (1,n+1): print(i, end='' ") print() Output: enter the number of rows:3 1 1 1 2 2 2 3 3 3 Please anybody explain me the body part , how this output came?

12th May 2021, 1:23 PM
Sachin Pradhan
Sachin Pradhan - avatar
1 Answer
+ 1
Well it's easy i is printing j numbers of times. mean when i is 1 then j is printing 3 times i means three times 1 and after that i became 2 and j has printed 3 times i means 3 times 2 and so on....
12th May 2021, 1:32 PM
Abhiyantā
Abhiyantā - avatar