+ 1
Can someone please explain the below question? Input was given and we have to find the output. I got the output like that. How?
Input:- for x in range (1 , 6): for y in range (1 , x+1): print(x , ' ' , y) Output:- 1 1 2 1 2 2 3 1 3 2 3 3 4 1 4 2 4 3 4 4 5 1 5 2 5 3 5 4 5 5 I would appreciate it if someone can explain it briefly how this works. I typed the input in python and that was the output I got. Please explain how? And Please don't spam and thank you
2 Réponses
+ 1
The second parameter in the range is not achieved, it's like ur saying for 1 <= x < 6 and for 1<= y < x+1
So first output x =1 and y=1
Since x+1 = 1 the internal loop will loop only once
X=2 y=1 and x+1=3 so the internal loop will loop twice (1,2)
And so one.
In order to understand how loops work, you need to identify your variables in each iteration x, y, x+1
0
Thank u for ur ans