1

Hi I am working with nested loops but can not figure out a way to start a new row for my nested loop below:

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

Output

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

The output I want is:

0 0 0 0 0 0 0 0 0 0

1 1 1 1 1 1 1 1 1 1

2 2 2 2 2 2 2 2 2 2

and so on

0

2 Answers 2

5

Thank you but I found the answer!

for i in range(0,10):
    for j in range(10):
        print(i, end=" ")
    print()
Sign up to request clarification or add additional context in comments.

Comments

0

This (and minor variations) also work:

for i in range(10):
    print((('%s '%i)*10)[:-1])

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.