Key Features

Experienced Teachers
Smart Classes
Regular Test
Study Material

Well qualified teachers with industrial experience.

To visualise or understand topics very easly.

We are organizing online and offline regular test.

We are providing prescribed study material.

Tuesday, December 29, 2020

Python Pattern Programs

 

In this article, I show you how to Print pattern in Python.
Today, We will cover the following Python pattern programs:
  • Number Pattern
  • Triangle Pattern with Number
  • Star (*) or Asterisk Pattern
  • Pyramid pattern
  • Inverted pyramid pattern
  • Half pyramid pattern
  • Diamond Shaped Pattern
  • Characters or Alphabets Pattern
  • Square pattern
SECTION : A

Section A : Pattern 1:

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

Programs :
rows = int(input("Enter the number of rows "))
for row in range(1, rows+1):
    for column in range(1, row + 1):
        print(row, end=' ')
    print("")
Section A : Pattern 2:

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

Programs :
rows = int(input("Enter the number of rows "))
for row in range(1, rows+1):
    for column in range(1, row + 1):
        print(column, end=' ')
    print("")
Section A : Pattern 3:

1 1 
1 1 1 
1 1 1 1 
1 1 1 1 1

Programs :
rows = int(input("Enter the number of rows "))
for row in range(1, rows+1):
    for column in range(1, row + 1):
        print("1", end=' ')
    print("")

SECTION : B

Section B : Pattern 1:

5 5 5 5 5 
5 5 5 5 
5 5 5 
5 5 
5

Programs :
rows = int(input("Enter number of rows "))
num = rows
for i in range(rows, 0, -1):
    for j in range(0, i):
        print(num, end=' ')
    print("\r")

Section B : Pattern 2:

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

Programs :
rows = int(input("enter number of rows "))
b = 0
for i in range(rows, 0, -1):
    b += 1
    for j in range(1, i + 1):
        print(b, end=' ')
    print('\r')

SECTION : C

Section C : Pattern 1:

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

Programs :
rows = int(input("Enter the number of rows ")) + 1
for row in range(1, rows):
    num = 1
    for j in range(rows, 0, -1):
        if j > row:
            print(" ", end=' ')
        else:
            print(num, end=' ')
            num += 1
    print("")

SECTION : D

Section D : Pattern 1:

            *
         * *
      * * *
   * * * *
* * * * *

Programs :
rows = int(input("Enter the size of pattern "))
k = 2 * rows - 2
for i in range(0, rows):
    for j in range(0, k):
        print(end=" ")
    k = k - 2
    for j in range(0, i + 1):
        print("* ", end="") 
    print("") 

SECTION : E


SECTION : F

Section F : Pattern 1:

*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*

Programs :
rows = int(input("Enter max star to be display on single line "))
for i in range(0, rows):
    for j in range(0, i + 1):
        print("*", end=' ')
    print("\r")

for i in range(rows, 0, -1):
    for j in range(0, i - 1):
        print("*", end=' ')
    print("\r")
Thank you very much for reading carefully, if you have any other questions, you can share it with us through comments, if this information was important to you, please let us know through comments.

Please do comment and share.
Thank You.

No comments:

Post a Comment