I would like to make a Pattern that give standard output

Viewed 67

Suppose the height is 4 and the width is 8

the result will:

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

i am a beginner i was trying it like

for i in range(height):
    for j in range(width):
        print(j, sep='  ', end=' ', flush=True)
    print()

but it need to print 1 to 9 and new line will be printed after the width , what should be the approach?

1 Answers

You have the right idea. I modified your code to use a counter variable, and then write it mod 10.

height = 4
width = 8

counter = 0
for i in range(height):
    for j in range(width):
        print(counter%10, sep='  ', end=' ', flush=True)
        counter+=1
    print()
Related