Number Pattern Programs in Python

If you are new to Java and want to learn the java coding skills too fast. Try practicing the core java programs with the help of the Java basic programs list available.

1) Number Pattern – 1

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For Loop.
  • Loop from 1 to iterator value of the parent For loop using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the Newline character after the end of the inner loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 8
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

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

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For Loop.
  • Loop from 1 to iterator value of the parent For loop using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the Newline character after the end of the inner loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 8
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 
1 2 3 4 5 6 7 
1 2 3 4 5 6 7 8

2) Number Pattern – 2

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For Loop.
  • Loop from 1 to iterator value of the parent For loop using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the Newline character after the end of the inner loop.
  • Loop from the number of rows-1 to 1 in decreasing order using For loop.
  • Loop from 1 to iterator value of the parent For loop using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the Newline character after the end of the inner loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 6
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()
# Loop from the number of rows-1 to 1 in decreasing order using For loop.
for m in range(numbOfRows-1, 0, -1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For Loop.
  • Loop from 1 to iterator value of the parent For loop using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the Newline character after the end of the inner loop.
  • Loop from the number of rows-1 to 1 in decreasing order using For loop.
  • Loop from 1 to iterator value of the parent For loop using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the Newline character after the end of the inner loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()
# Loop from the number of rows-1 to 1 in decreasing order using For loop.
for m in range(numbOfRows-1, 0, -1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 8
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 
1 2 3 4 5 6 7 
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 
1 2 3 4 5 6 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1

3) Number Pattern – 3

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the parent loop with space in the inner For loop. (This prints the same number parent loop number of times)
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 8
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Print the iterator value of the nested loop with space in the inner For loop.
        # (This prints the same number parent loop number of times)
        print(m, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

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

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the parent loop with space in the inner For loop. (This prints the same number parent loop number of times)
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Print the iterator value of the nested loop with space in the inner For loop.
        # (This prints the same number parent loop number of times)
        print(m, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 6
1 
2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5 
6 6 6 6 6 6

4) Number Pattern – 4

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the number of rows to iterator value>=m in decreasing order using another For Loop(Inner For loop) where m is the iterator value of the parent For loop.
  • Print the iterator value of the inner For loop.
  • Print the Newline character after the end of the inner loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 10
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the number of rows to iterator value>=m in decreasing order
    # using another For Loop(Inner For loop)
    # where m is the iterator value of the parent For loop.
    for n in range(numbOfRows, m-1, -1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

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

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the number of rows to m in decreasing order using another For Loop(Inner For loop) where m is the iterator value of the parent For loop.
  • Print the iterator value of the inner For loop.
  • Print the Newline character after the end of the inner loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the number of rows to iterator value>=m in decreasing order
    # using another For Loop(Inner For loop)
    # where m is the iterator value of the parent For loop.
    for n in range(numbOfRows, m-1, -1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 9
9 8 7 6 5 4 3 2 1 
9 8 7 6 5 4 3 2 
9 8 7 6 5 4 3 
9 8 7 6 5 4 
9 8 7 6 5 
9 8 7 6 
9 8 7 
9 8 
9

5) Number Pattern – 5

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 9
# Loop from the number of rows to 1(included) in decreasing order.
for m in range(numbOfRows, 0, -1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

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

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from the number of rows to 1(included) in decreasing order.
for m in range(numbOfRows, 0, -1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 5
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1

6) Number Pattern – 6

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order using For loop.
  • Loop from iterator value of the parent For loop to 1(included) in decreasing order using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 11
# Loop from the number of rows to 1(included) in decreasing order using For loop.
for m in range(numbOfRows, 0, -1):
    # Loop from iterator value of the parent For loop to 1(included)
    # in decreasing order using another Nested For loop.
    for n in range(m, 0, -1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

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

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order using For loop.
  • Loop from iterator value of the parent For loop to 1(included) in decreasing order using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from the number of rows to 1(included) in decreasing order using For loop.
for m in range(numbOfRows, 0, -1):
    # Loop from iterator value of the parent For loop to 1(included)
    # in decreasing order using another Nested For loop.
    for n in range(m, 0, -1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 8
8 7 6 5 4 3 2 1 
7 6 5 4 3 2 1 
6 5 4 3 2 1 
5 4 3 2 1 
4 3 2 1 
3 2 1 
2 1 
1

7) Number Pattern – 7

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order using For loop.
  • Loop from the number of rows to m in decreasing order using another For Loop(Inner For loop) where m is the iterator value of the parent For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows =6
# Loop from the number of rows to 1(included) in decreasing order.
for m in range(numbOfRows, 0, -1):
    # Loop from the number of rows to m in decreasing order using
    # another For Loop(Inner For loop)
    # where m is the iterator value of the parent For loop.
    for n in range(numbOfRows, m-1, -1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

6 
6 5 
6 5 4 
6 5 4 3 
6 5 4 3 2 
6 5 4 3 2 1

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order using For loop.
  • Loop from iterator value of the parent For loop to 1(included) in decreasing order using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

Output:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from the number of rows to 1(included) in decreasing order using For loop.
for m in range(numbOfRows, 0, -1):
    # Loop from the number of rows to m in decreasing order using
    # another For Loop(Inner For loop)
    # where m is the iterator value of the parent For loop.
    for n in range(numbOfRows, m-1, -1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 8
8 
8 7 
8 7 6 
8 7 6 5 
8 7 6 5 4 
8 7 6 5 4 3 
8 7 6 5 4 3 2 
8 7 6 5 4 3 2 1

8) Number Pattern – 8

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Loop from iterator value of the parent For loop -1 to 1(included) in decreasing order using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 9
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    '''Loop from iterator value of the parent For loop -1 to 1(included) 
    in decreasing order using another For loop(Inner For Loop). '''
    for n in range(m-1, 0, -1):
       # Print the iterator value of the inner For loop.
        print(n, end=' ')

    # Print the Newline character after the end of the inner loop.
    print(

Output:

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

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Loop from iterator value of the parent For loop -1 to 1(included) in decreasing order using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    '''Loop from iterator value of the parent For loop -1 to 1(included) 
    in decreasing order using another For loop(Inner For Loop). '''
    for n in range(m-1, 0, -1):
       # Print the iterator value of the inner For loop.
        print(n, end=' ')

    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 10
1 
1 2 1 
1 2 3 2 1 
1 2 3 4 3 2 1 
1 2 3 4 5 4 3 2 1 
1 2 3 4 5 6 5 4 3 2 1 
1 2 3 4 5 6 7 6 5 4 3 2 1 
1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 
1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1 
1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1

9) Number Pattern – 9

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • Loop from 2 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 8
# Loop from the number of rows to 1(included) in decreasing order.
for m in range(numbOfRows, 0, -1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()
# Loop from 2 to the number of rows using For Loop.
for m in range(2, numbOfRows+1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

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

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • Loop from 2 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from the number of rows to 1(included) in decreasing order.
for m in range(numbOfRows, 0, -1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()
# Loop from 2 to the number of rows using For Loop.
for m in range(2, numbOfRows+1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 11
1 2 3 4 5 6 7 8 9 10 11 
1 2 3 4 5 6 7 8 9 10 
1 2 3 4 5 6 7 8 9 
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 
1 2 3 4 5 6 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 
1 2 3 4 5 6 7 
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 8 9 
1 2 3 4 5 6 7 8 9 10 
1 2 3 4 5 6 7 8 9 10 11

10) Number Pattern – 10

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from the 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print Two spaces.
  • Loop from the first loop iterator value to the number of rows(included) using Another For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • Loop from the number of rows -1 to 1(included) in decreasing order using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print Two spaces.
  • Loop from the first loop iterator value to the number of rows(included) using Another For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 8
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print Two spaces.
        print(' ', end=' ')
    # Loop from the first loop iterator value to the number of rows(included)
    # using Another For loop.
    for n in range(m, numbOfRows+1):
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

# Loop from the number of rows -1 to 1(included) in decreasing order using For loop.
for m in range(numbOfRows-1, 0, -1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print Two spaces.
        print(' ', end=' ')
    # Loop from the first loop iterator value to the number of rows(included)
    # using Another For loop.
    for n in range(m, numbOfRows+1):
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

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

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from the 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print Two spaces.
  • Loop from the first loop iterator value to the number of rows(included) using Another For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • Loop from the number of rows -1 to 1(included) in decreasing order using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print Two spaces.
  • Loop from the first loop iterator value to the number of rows(included) using Another For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print Two spaces.
        print(' ', end=' ')
    # Loop from the first loop iterator value to the number of rows(included)
    # using Another For loop.
    for n in range(m, numbOfRows+1):
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

# Loop from the number of rows -1 to 1(included) in decreasing order using For loop.
for m in range(numbOfRows-1, 0, -1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print Two spaces.
        print(' ', end=' ')
    # Loop from the first loop iterator value to the number of rows(included)
    # using Another For loop.
    for n in range(m, numbOfRows+1):
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 8
1 2 3 4 5 6 7 8 
   2 3 4 5 6 7 8 
      3 4 5 6 7 8 
         4 5 6 7 8 
            5 6 7 8 
               6 7 8 
                  7 8 
                     8 
                  7 8 
               6 7 8 
            5 6 7 8 
         4 5 6 7 8  
      3 4 5 6 7 8  
   2 3 4 5 6 7 8 
1 2 3 4 5 6 7 8

11) Number Pattern – 11

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from iterator value of the parent For loop to 1(included) in decreasing order using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 10
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from iterator value of the parent For loop to 1(included)
    # in decreasing order
    # using another Nested For loop.
    for n in range(m, 0, -1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

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

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from iterator value of the parent For loop to 1(included) in decreasing order using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from iterator value of the parent For loop to 1(included)
    # in decreasing order
    # using another Nested For loop.
    for n in range(m, 0, -1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 7
1 
2 1 
3 2 1 
4 3 2 1 
5 4 3 2 1 
6 5 4 3 2 1 
7 6 5 4 3 2 1

12) Number Pattern – 12

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Check if the iterator value of the inner For loop is divisible by 2 or not using the If statement.
  • If it is true then print 0.
  • Else print 1.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 8
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Check if the iterator value of the inner For loop is divisible by 2
        # or not using the If statement.
        if(n % 2 == 0):
            # If it is true then print 0.
            print('0', end='')
           # Else print 1.
        else:
            print('1', end='')

    # Print the newline character after ending of inner For loop.
    print()

Output:

1
10
101
1010
10101
101010
1010101
10101010

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Check if the iterator value of the inner For loop is divisible by 2 or not using the If statement.
  • If it is true then print 0.
  • Else print 1.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Check if the iterator value of the inner For loop is divisible by 2
        # or not using the If statement.
        if(n % 2 == 0):
            # If it is true then print 0.
            print('0', end='')
           # Else print 1.
        else:
            print('1', end='')

    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 11
1
10
101
1010
10101
101010
1010101
10101010
101010101
1010101010
10101010101

13) Number Pattern – 13

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from 1 to the number of rows using another Nested For loop.
  • Check if the iterator value of the inner For loop is equal to the iterator value of the parent For loop or not using the If statement.
  • If it is true then print the iterator value of the inner For Loop.
  • Else print 0.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 8
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to the number of rows using another Nested For loop.
    for n in range(1, numbOfRows+1):
        # Check if the iterator value of the inner For loop is equal to the iterator value of the parent
        # For loop or not using the If statement.
        if(n == m):
            # If it is true then print n.
            print(n, end=' ')
           # Else print 0.
        else:
            print('0', end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

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

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from 1 to the number of rows using another Nested For loop.
  • Check if the iterator value of the inner For loop is equal to the iterator value of the parent For loop or not using the If statement.
  • If it is true then print the iterator value of the inner For Loop.
  • Else print 0.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to the number of rows using another Nested For loop.
    for n in range(1, numbOfRows+1):
        # Check if the iterator value of the inner For loop is equal to the iterator value of the parent
        # For loop or not using the If statement.
        if(n == m):
            # If it is true then print n.
            print(n, end=' ')
           # Else print 0.
        else:
            print('0', end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 6
1 0 0 0 0 0 
0 2 0 0 0 0 
0 0 3 0 0 0 
0 0 0 4 0 0 
0 0 0 0 5 0 
0 0 0 0 0 6

14) Number Pattern – 14

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from the 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the space character.
  • Loop from the first loop iterator value to the number of rows(included) using Another For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • Loop from the number of rows -1 to 1(included) in decreasing order using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the space character.
  • Loop from the first loop iterator value to the number of rows(included) using Another For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 6
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print the space character.
        print(end=' ')
    # Loop from the first loop iterator value to the number of rows(included)
    # using Another For loop.
    for n in range(m, numbOfRows+1):
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

# Loop from the number of rows -1 to 1(included) in decreasing order using For loop.
for m in range(numbOfRows-1, 0, -1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print the space character.
        print(end=' ')
    # Loop from the first loop iterator value to the number of rows(included)
    # using Another For loop.
    for n in range(m, numbOfRows+1):
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

1 2 3 4 5 6 
 2 3 4 5 6 
  3 4 5 6 
   4 5 6 
    5 6 
     6 
    5 6 
   4 5 6 
  3 4 5 6 
 2 3 4 5 6 
1 2 3 4 5 6

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from the 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the space character.
  • Loop from the first loop iterator value to the number of rows(included) using Another For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • Loop from the number of rows -1 to 1(included) in decreasing order using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the space character.
  • Loop from the first loop iterator value to the number of rows(included) using Another For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print the space character.
        print(end=' ')
    # Loop from the first loop iterator value to the number of rows(included)
    # using Another For loop.
    for n in range(m, numbOfRows+1):
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

# Loop from the number of rows -1 to 1(included) in decreasing order using For loop.
for m in range(numbOfRows-1, 0, -1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print the space character.
        print(end=' ')
    # Loop from the first loop iterator value to the number of rows(included)
    # using Another For loop.
    for n in range(m, numbOfRows+1):
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 8
1 2 3 4 5 6 7 
 2 3 4 5 6 7 
  3 4 5 6 7 
   4 5 6 7 
    5 6 7 
     6 7 
      7 
     6 7 
    5 6 7 
   4 5 6 7 
  3 4 5 6 7 
 2 3 4 5 6 7 
1 2 3 4 5 6 7

15) Number Pattern – 15

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from the 1 to the number of rows using For loop.
  • Loop from 1 to the number of rows -first loop iterator value using another Nested For loop.
  • Print 1.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the parent For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 9
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to the number of rows -first loop iterator
    # value using another Nested For loop.
    for n in range(1, numbOfRows-m+1):
        # Print 1.
        print('1', end=' ')

    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print the iterator value of the parent For loop.
        print(m, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

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

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from the 1 to the number of rows using For loop.
  • Loop from 1 to the number of rows -first loop iterator value using another Nested For loop.
  • Print 1.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the parent For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to the number of rows -first loop iterator
    # value using another Nested For loop.
    for n in range(1, numbOfRows-m+1):
        # Print 1.
        print('1', end=' ')

    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print the iterator value of the parent For loop.
        print(m, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 6
1 1 1 1 1 
1 1 1 1 2 
1 1 1 3 3 
1 1 4 4 4 
1 5 5 5 5 
6 6 6 6 6

16) Number Pattern – 16

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from the 1 to the number of rows using For loop.
  • Loop from the iterator value of the parent For loop to the number of rows using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 9
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from the iterator value of the parent For loop to the number of rows
    # using another Nested For loop.
    for n in range(m, numbOfRows+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

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

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from the 1 to the number of rows using For loop.
  • Loop from the iterator value of the parent For loop to the number of rows using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from the iterator value of the parent For loop to the number of rows
    # using another Nested For loop.
    for n in range(m, numbOfRows+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 11
1 2 3 4 5 6 7 8 9 10 11 
2 3 4 5 6 7 8 9 10 11 1 
3 4 5 6 7 8 9 10 11 1 2 
4 5 6 7 8 9 10 11 1 2 3 
5 6 7 8 9 10 11 1 2 3 4 
6 7 8 9 10 11 1 2 3 4 5 
7 8 9 10 11 1 2 3 4 5 6 
8 9 10 11 1 2 3 4 5 6 7 
9 10 11 1 2 3 4 5 6 7 8 
10 11 1 2 3 4 5 6 7 8 9 
11 1 2 3 4 5 6 7 8 9 10

17) Number Pattern – 17

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Take a variable and initialize it with 1 say sampNumber.
  • Loop from 1 to the number of rows of the triangle using For loop.
  • Using another For loop, loop from 1 to the parent loop iterator value (Nested For loop).
  • Inside the inner for loop print the sampNumber with a space character.
  • Increase the value of sampNum by 1.
  • Print the Newline Character after the end of the inner for loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows of the triangle as static input and store it in a variable.
numbOfRows = 4
# Take a variable and initialize it with 1 say sampNumber.
sampNumber = 1
# Loop from 1 to the number of rows of the triangle using For loop.
for m in range(1, numbOfRows+1):
  # Using another For loop, loop from 1 to the parent loop iterator value (Nested For loop).
    for n in range(1, m+1):
        # Inside the inner for loop print the sampNumber with a space character.
        print(sampNumber, end=' ')
        # Increase the value of sampNumber by 1.
        sampNumber = sampNumber+1
    # Print the Newline Character after the end of the inner for loop.
    print()

Output:

1 
2 3 
4 5 6 
7 8 9 10

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Take a variable and initialize it with 1 say sampNumber.
  • Loop from 1 to the number of rows of the triangle using For loop.
  • Using another For loop, loop from 1 to the parent loop iterator value (Nested For loop).
  • Inside the inner for loop print the sampNumber with a space character.
  • Increase the value of sampNum by 1.
  • Print the Newline Character after the end of the inner for loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Take a variable and initialize it with 1 say sampNumber.
sampNumber = 1
# Loop from 1 to the number of rows of the triangle using For loop.
for m in range(1, numbOfRows+1):
  # Using another For loop, loop from 1 to the parent loop iterator value (Nested For loop).
    for n in range(1, m+1):
        # Inside the inner for loop print the sampNumber with a space character.
        print(sampNumber, end=' ')
        # Increase the value of sampNumberby 1.
        sampNumber = sampNumber+1
    # Print the Newline Character after the end of the inner for loop.
    print()

Output:

Enter some random number of rows = 6
1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15 
16 17 18 19 20 21

18) Number Pattern – 18

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Take a variable and initialize its value with the iterator value of the parent For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the samp value.
  • Modify the samp by samp+number of rows – n, where n is the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 9
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Take a variable and initialize its value with the
    # iterator value of the parent For loop.
    samp = m
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Print the samp value.
        print(samp, end=' ')
        # Modify the samp by samp+number of rows - n,
        # where n is the iterator value of the inner For loop.
        samp = samp+numbOfRows-n
    # Print the newline character after ending of inner For loop.
    print()

Output:

1 
2 10 
3 11 18 
4 12 19 25 
5 13 20 26 31 
6 14 21 27 32 36 
7 15 22 28 33 37 40 
8 16 23 29 34 38 41 43 
9 17 24 30 35 39 42 44 45

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Take a variable and initialize its value with the iterator value of the parent For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the samp value.
  • Modify the samp by samp+number of rows – n, where n is the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Take a variable and initialize its value with the
    # iterator value of the parent For loop.
    samp = m
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Print the samp value.
        print(samp, end=' ')
        # Modify the samp by samp+number of rows - n,
        # where n is the iterator value of the inner For loop.
        samp = samp+numbOfRows-n
    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 9
1 
2 10 
3 11 18 
4 12 19 25 
5 13 20 26 31 
6 14 21 27 32 36 
7 15 22 28 33 37 40 
8 16 23 29 34 38 41 43 
9 17 24 30 35 39 42 44 45

19) Number Pattern – 19

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows of the triangle using For loop.
  • Take a variable and initialize it with the iterator value of the parent For loop say samp.
  • Loop from iterator value of the Parent For loop to 1(included) in decreasing order using another Nested For loop.
  • Inside the inner for loop print the samp with a space character.
  • Increase the value of samp by the number of rows.
  • Print the Newline Character after the end of the inner for loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 8
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Take a variable and initialize it with the iterator value of
    # the parent For loop say samp.
    samp = m
    # Loop from iterator value of the Parent For loop to 1(included)
    # in decreasing order using another Nested For loop.
    for n in range(m, 0, -1):
        # Inside the inner for loop print the samp with a space character.
        print(samp, end=' ')
        # Increase the value of samp by the number of rows.
        samp = samp+numbOfRows
    # Print the newline character after ending of inner For loop.
    print()

Output:

1 
2 10 
3 11 19 
4 12 20 28 
5 13 21 29 37 
6 14 22 30 38 46 
7 15 23 31 39 47 55 
8 16 24 32 40 48 56 64

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows of the triangle using For loop.
  • Take a variable and initialize it with the iterator value of the parent For loop say samp.
  • Loop from iterator value of the Parent For loop to 1(included) in decreasing order using another Nested For loop.
  • Inside the inner for loop print the samp with a space character.
  • Increase the value of samp by the number of rows.
  • Print the Newline Character after the end of the inner for loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Take a variable and initialize it with the iterator value of
    # the parent For loop say samp.
    samp = m
    # Loop from iterator value of the Parent For loop to 1(included)
    # in decreasing order using another Nested For loop.
    for n in range(m, 0, -1):
        # Inside the inner for loop print the samp with a space character.
        print(samp, end=' ')
        # Increase the value of samp by the number of rows.
        samp = samp+numbOfRows
    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 9
1 
2 11 
3 12 21 
4 13 22 31 
5 14 23 32 41 
6 15 24 33 42 51 
7 16 25 34 43 52 61 
8 17 26 35 44 53 62 71 
9 18 27 36 45 54 63 72 81

20) Number Pattern – 20

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order using For loop.
  • Loop from 1 to iterator value of the parent For loop using another Nested For loop.
  • Inside the inner for loop print the space character.
  • Loop from parent loop iterator value to the number of rows using another For loop(Inner For loop).
  • Print the iterator value of the inner For loop.
  • Print the Newline Character after the end of the inner for loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 9
# Loop from the number of rows to 1(included) in decreasing order using For loop.
for m in range(numbOfRows, 0, -1):
    # Loop from 1 to iterator value of the parent For loop using another Nested For loop.
    for n in range(1, m):
        # Inside the inner for loop print the space character.
        print(end=' ')
    # Loop from parent loop iterator value to the number of rows
    # using another For loop(Inner For loop).
    for n in range(m, numbOfRows+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

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

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order using For loop.
  • Loop from 1 to iterator value of the parent For loop using another Nested For loop.
  • Inside the inner for loop print the space character.
  • Loop from parent loop iterator value to the number of rows using another For loop(Inner For loop).
  • Print the iterator value of the inner For loop.
  • Print the Newline Character after the end of the inner for loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from the number of rows to 1(included) in decreasing order using For loop.
for m in range(numbOfRows, 0, -1):
    # Loop from 1 to iterator value of the parent For loop using another Nested For loop.
    for n in range(1, m):
        # Inside the inner for loop print the space character.
        print(end=' ')
    # Loop from parent loop iterator value to the number of rows
    # using another For loop(Inner For loop).
    for n in range(m, numbOfRows+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 9
        9 
       8 9 
      7 8 9 
     6 7 8 9 
    5 6 7 8 9 
   4 5 6 7 8 9 
  3 4 5 6 7 8 9 
 2 3 4 5 6 7 8 9 
1 2 3 4 5 6 7 8 9

21) Number Pattern – 21

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the first loop iterator value to the number of rows using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Loop from the number of rows-1 to iterator value of the parent For loop (included) in decreasing order using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 9
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the first loop iterator value
    # to the number of rows using another Nested For loop.
    for n in range(m, numbOfRows+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    '''Loop from the number of rows-1 to iterator value of the parent For loop (included)
    in decreasing order using another For loop(Inner For Loop). '''
    for n in range(numbOfRows-1, m-1, -1):
       # Print the iterator value of the inner For loop.
        print(n, end=' ')

    # Print the Newline character after the end of the inner loop.
    print()

Output:

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

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the first loop iterator value to the number of rows using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Loop from the number of rows-1 to iterator value of the parent For loop (included) in decreasing order using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the first loop iterator value
    # to the number of rows using another Nested For loop.
    for n in range(m, numbOfRows+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    '''Loop from the number of rows-1 to iterator value of the parent For loop (included)
    in decreasing order using another For loop(Inner For Loop). '''
    for n in range(numbOfRows-1, m-1, -1):
       # Print the iterator value of the inner For loop.
        print(n, end=' ')

    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 13
1 2 3 4 5 6 7 8 9 10 11 12 13 12 11 10 9 8 7 6 5 4 3 2 1 
2 3 4 5 6 7 8 9 10 11 12 13 12 11 10 9 8 7 6 5 4 3 2 
3 4 5 6 7 8 9 10 11 12 13 12 11 10 9 8 7 6 5 4 3 
4 5 6 7 8 9 10 11 12 13 12 11 10 9 8 7 6 5 4 
5 6 7 8 9 10 11 12 13 12 11 10 9 8 7 6 5 
6 7 8 9 10 11 12 13 12 11 10 9 8 7 6 
7 8 9 10 11 12 13 12 11 10 9 8 7 
8 9 10 11 12 13 12 11 10 9 8 
9 10 11 12 13 12 11 10 9 
10 11 12 13 12 11 10 
11 12 13 12 11 
12 13 12 
13

22) Number Pattern – 22

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the number of rows to the iterator value of the parent For loop using another For loop(Inner For loop).
  • Print the space character.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the first loop iterator value.
  • Print the newline character after ending of inner For loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 9
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the number of rows to the iterator value of the parent
    # For loop using another For loop(Inner For loop).
    for n in range(numbOfRows, m, -1):
        # Print the space character.
        print(end=' ')
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
       # Print the first loop iterator value.
        print(m, end=' ')

    # Print the Newline character after the end of the inner loop.
    print()

Output:

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

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the number of rows to the iterator value of the parent For loop using another For loop(Inner For loop).
  • Print the space character.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the first loop iterator value.
  • Print the newline character after ending of inner For loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the number of rows to the iterator value of the parent
    # For loop using another For loop(Inner For loop).
    for n in range(numbOfRows, m, -1):
        # Print the space character.
        print(end=' ')
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
       # Print the first loop iterator value.
        print(m, end=' ')

    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 7
      1 
     2 2 
    3 3 3 
   4 4 4 4 
  5 5 5 5 5 
 6 6 6 6 6 6 
7 7 7 7 7 7 7

23) Number Pattern – 23

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 0 to the number of rows using For loop.
  • Loop from 0 to the number of rows using another For loop(Inner For loop).
  • Check if the inner Loop iterator value is divisible by 2 or not using the If statement.
  • If it is divisible then print (number of rows * n)+m+1 Where m is the iterator value of the parent For loop and n is the iterator value of the inner For loop.
  • Else print (number of rows * (n+1) ) -m.
  • Print the newline character after ending of inner For loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 4
# Loop from 0 to the number of rows using For loop.
for m in range(0, numbOfRows):
    # Loop from 0 to the number of rows using another For loop(Inner For loop).
    for n in range(0, numbOfRows):
        # Check if the inner Loop iterator value is divisible by 2 or not
        # using the If statement.
        if(n % 2 == 0):
            # If it is divisible then print (number of rows * n)+m+1
            # Where m is the iterator value of the parent For loop
            # and n is the iterator value of the inner For loop.
            print((numbOfRows*n)+m+1, end=' ')
        # Else print (number of rows * (n+1) ) -m.
        else:
            print((numbOfRows * (n+1)) - m, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

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

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 0 to the number of rows using For loop.
  • Loop from 0 to the number of rows using another For loop(Inner For loop).
  • Check if the inner Loop iterator value is divisible by 2 or not using the If statement.
  • If it is divisible then print (number of rows * n)+m+1 Where m is the iterator value of the parent For loop and n is the iterator value of the inner For loop.
  • Else print (number of rows * (n+1) ) -m.
  • Print the newline character after ending of inner For loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 0 to the number of rows using For loop.
for m in range(0, numbOfRows):
    # Loop from 0 to the number of rows using another For loop(Inner For loop).
    for n in range(0, numbOfRows):
        # Check if the inner Loop iterator value is divisible by 2 or not
        # using the If statement.
        if(n % 2 == 0):
            # If it is divisible then print (number of rows * n)+m+1
            # Where m is the iterator value of the parent For loop
            # and n is the iterator value of the inner For loop.
            print((numbOfRows*n)+m+1, end=' ')
        # Else print (number of rows * (n+1) ) -m.
        else:
            print((numbOfRows * (n+1)) - m, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 5
1 10 11 20 21 
2 9 12 19 22 
3 8 13 18 23 
4 7 14 17 24 
5 6 15 16 25

24) Number Pattern – 24

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the iterator value of the parent For loop to the number of rows using another For loop(Inner For loop).
  • Print the inner loop iterator value.
  • Loop from iterator value of the parent For loop-1 to 1(included) in decreasing order using another Inner For loop.
  • Print the inner loop iterator value.
  • Print the newline character after ending of inner For loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 7
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the iterator value of the parent For loop to the
    # number of rows using another For loop(Inner For loop).
    for n in range(m, numbOfRows+1):
        # Print the inner loop iterator value.
        print(n, end=' ')
    # Loop from iterator value of the parent For loop-1 to 1(included)
    # in decreasing order
    # using another Inner For loop.
    for n in range(m-1, 0, -1):
        # Print the inner loop iterator value
        print(n, end=' ')

    # Print the Newline character after the end of the inner loop.
    print()

Output:

1 2 3 4 5 6 7 
2 3 4 5 6 7 1 
3 4 5 6 7 2 1 
4 5 6 7 3 2 1 
5 6 7 4 3 2 1 
6 7 5 4 3 2 1 
7 6 5 4 3 2 1

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the iterator value of the parent For loop to the number of rows using another For loop(Inner For loop).
  • Print the inner loop iterator value.
  • Loop from iterator value of the parent For loop-1 to 1(included) in decreasing order using another Inner For loop.
  • Print the inner loop iterator value.
  • Print the newline character after ending of inner For loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the iterator value of the parent For loop to the
    # number of rows using another For loop(Inner For loop).
    for n in range(m, numbOfRows+1):
        # Print the inner loop iterator value.
        print(n, end=' ')
    # Loop from iterator value of the parent For loop-1 to 1(included)
    # in decreasing order
    # using another Inner For loop.
    for n in range(m-1, 0, -1):
        # Print the inner loop iterator value
        print(n, end=' ')

    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 8
1 2 3 4 5 6 7 8 
2 3 4 5 6 7 8 1 
3 4 5 6 7 8 2 1 
4 5 6 7 8 3 2 1 
5 6 7 8 4 3 2 1 
6 7 8 5 4 3 2 1 
7 8 6 5 4 3 2 1 
8 7 6 5 4 3 2 1

25) Number Pattern – 25

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the number of rows to the iterator value of the parent For loop using another For loop(Inner For loop).
  • Print the space character.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the inner loop iterator value.
  • Print the newline character after ending of inner For loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 9
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the number of rows to the iterator value of the parent
    # For loop using another For loop(Inner For loop).
    for n in range(numbOfRows, m, -1):
        # Print the space character.
        print(end=' ')
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
       # Print the inner loop iterator value.
        print(n, end=' ')

    # Print the Newline character after the end of the inner loop.
    print()

Output:

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

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the number of rows to the iterator value of the parent For loop using another For loop(Inner For loop).
  • Print the space character.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the inner loop iterator value.
  • Print the newline character after ending of inner For loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the number of rows to the iterator value of the parent
    # For loop using another For loop(Inner For loop).
    for n in range(numbOfRows, m, -1):
        # Print the space character.
        print(end=' ')
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
       # Print the inner loop iterator value.
        print(n, end=' ')

    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 13
            1 
           1 2 
          1 2 3 
         1 2 3 4 
        1 2 3 4 5 
       1 2 3 4 5 6 
      1 2 3 4 5 6 7 
     1 2 3 4 5 6 7 8 
    1 2 3 4 5 6 7 8 9 
   1 2 3 4 5 6 7 8 9 10 
  1 2 3 4 5 6 7 8 9 10 11 
 1 2 3 4 5 6 7 8 9 10 11 12 
1 2 3 4 5 6 7 8 9 10 11 12 13