-4

In python I tried to make table like this

1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10

I tried this code:

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

but it outputs:

1 2 3 4 5 6 7 8 9 1
1 2 3 4 5 6 7 8 9 2
1 2 3 4 5 6 7 8 9 3
1 2 3 4 5 6 7 8 9 4
1 2 3 4 5 6 7 8 9 5
1 2 3 4 5 6 7 8 9 6
1 2 3 4 5 6 7 8 9 7
1 2 3 4 5 6 7 8 9 8
1 2 3 4 5 6 7 8 9 9
1 2 3 4 5 6 7 8 9 10
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
SladeGeo
  • 5
  • 2
  • 4
    The problem lies in your j-for loop's range(1,10) and your stray print(i) statement after the j-for loop. `for j in range(1,10)` will produce a range from 1 through 9, so that's what you see printed in your output. Then you `print(i)` after this loop, which shows as the last number in each line of your output. Try changing things around to understand what your for loop is doing and what your print statements are contributing to. – Endyd Jan 08 '19 at 19:10

2 Answers2

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

or

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

You don't actually want to print i in the outer loop. You only need the print statement there for your line break. You can change how many columns there are y modifying the range in the inner loop (j loop)

Endyd
  • 1,249
  • 6
  • 12
0

Your outer loop is only used to count the number of rows that will be printed. Seems like you want a 10x10 table, so you have 10 rows.

for row in range(10):

Then you want the numbers 1 through 10 printed on each row:

for column in range(1,11):
    print(column, end=' ')

Then you want to write a newline so that each row shows up on a new line.

print()

That should do it.

Endyd
  • 1,249
  • 6
  • 12