Home > Net >  how to get that output with nested for python
how to get that output with nested for python

Time:10-28

how to get that output with nested for python
I've tried but haven't got that kind of output

0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
2 3 4 5 6 7 8 9 10 11
3 4 5 6 7 8 9 10 11 12
4 5 6 7 8 9 10 11 12 13
5 6 7 8 9 10 11 12 13 14
6 7 8 9 10 11 12 13 14 15
7 8 9 10 11 12 13 14 15 16
8 9 10 11 12 13 14 15 16 17
9 10 11 12 13 14 15 16 17 18

CodePudding user response:

You can create a list then in each iterate print list then add one to all element like below:

lst = [0,1,2,3,4,5,6,7,8,9]
for _ in range(10):
    print(*lst, sep=' ')
    lst = [l 1 for l in lst]

Output:

0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
2 3 4 5 6 7 8 9 10 11
3 4 5 6 7 8 9 10 11 12
4 5 6 7 8 9 10 11 12 13
5 6 7 8 9 10 11 12 13 14
6 7 8 9 10 11 12 13 14 15
7 8 9 10 11 12 13 14 15 16
8 9 10 11 12 13 14 15 16 17
9 10 11 12 13 14 15 16 17 18

CodePudding user response:

for i in range(10):
    for j in range(i, i 10):
        print(j, end = " ")
    print()

CodePudding user response:

i = 0
while i!=10:
    c = ''
    for j in range(i,i 10):
        c = c   str(j)   " "
    print(c)
    i =1
  • Related