DEV Community

Cover image for Python Pattern Problems
G Gokul
G Gokul

Posted on

Python Pattern Problems

program:

for row in range(1,6):
    for col in range(1,6):
        print("*", end =' ')
    print()
Enter fullscreen mode Exit fullscreen mode

output:

 * * * * * 
 * * * * * 
 * * * * * 
 * * * * * 
 * * * * *
Enter fullscreen mode Exit fullscreen mode

program:

for row in range(1,6):
    print(row, end =' ')
    for col in range(1,row):
        print("*", end =' ')
    print()
Enter fullscreen mode Exit fullscreen mode

output:
1
2 *
3 * *
4 * * *
5 * * * *
program:

for row in range(2,7):
    for col in range(1,row):
        print("*", end =' ')
    print()
Enter fullscreen mode Exit fullscreen mode

output:

 * 
 * * 
 * * * 
 * * * * 
 * * * * *
Enter fullscreen mode Exit fullscreen mode

program:

for row in range(2,7):
    for col in range(1,row):
        print(col, end =' ')
    print()
Enter fullscreen mode Exit fullscreen mode

output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

program:

for row in range(2,7):
    for col in range(1,row):
        print(col - row, end =' ')
    print()
Enter fullscreen mode Exit fullscreen mode

output:
-1
-2 -1
-3 -2 -1
-4 -3 -2 -1
-5 -4 -3 -2 -1

program:

for row in range(1,6):
    for col in range(1,row + 1):
        print(row, end =' ')
    print()
Enter fullscreen mode Exit fullscreen mode

output:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

program:

for row in range(1,6):
    for col in range(1,row + 1):
        print(row * col, end =' ')
    print()
Enter fullscreen mode Exit fullscreen mode

output:
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25

program:

for row in range(2,7):
    for col in range(1,row):
        print(row * col, end =' ')
    print()
Enter fullscreen mode Exit fullscreen mode

output:
2
3 6
4 8 12
5 10 15 20
6 12 18 24 30

program:

for row in range(2,7):
    for col in range(1,row):
        print((row - 1) * col, end =' ')
    print()
Enter fullscreen mode Exit fullscreen mode

output:
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25

program:

for row in range(1,6):
    for col in range(1,row + 1):
        print((col + 1) * row, end =' ')
    print()
Enter fullscreen mode Exit fullscreen mode

output:
2
4 6
6 9 12
8 12 16 20
10 15 20 25 30

program:

for row in range(2,7):
    for col in range(1,row):
        print((row - col) -1, end =' ')
    print()
Enter fullscreen mode Exit fullscreen mode

output:
0
1 0
2 1 0
3 2 1 0
4 3 2 1 0

Top comments (0)