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

foor loop problem

for i in range(10): for num in range(i): print(i,end=" ") print(/n) please explain me this code...

28th Dec 2021, 7:16 PM
baker hosen
5 Answers
+ 3
I think indentation got messed up – put it in a script on sololearn playground and link it and check the indentation. Also check the 2nd print statement – it will give an error
28th Dec 2021, 7:33 PM
Lisa
Lisa - avatar
0
Look, this is what you expected? https://code.sololearn.com/cYXM2NwUvLE1/?ref=app
28th Dec 2021, 8:09 PM
CGM
CGM - avatar
0
for i in range(10) : for num in range(i) : print(i, end=" ") print("") Output : 1 1 2 2 2 3 3 3 3 4 4 4 4 4 5 5 5 5 5 5 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9
28th Dec 2021, 8:29 PM
VCoder
VCoder - avatar
0
VCoder , that is not the output that I get, in python the last number in range() is not included.
28th Dec 2021, 8:40 PM
CGM
CGM - avatar
0
That's true, i forgot to write range(i + 1) and Output : 0 ...
28th Dec 2021, 10:17 PM
VCoder
VCoder - avatar