Search the Blog

Python

As all of us knows that as we used to print the pattern program in C, C++, JAVA, etc. to make comfortable to the user we started learning that programming language.

In the same way to make confidence and learn syntax and logic writting style in Python we can practice for this i am showing to all of you more than 20 pattern program code in Python.
You can copy and paste these code and even test at your own system. Users can modify these Codes too.




---------------------------------------------------------------------------------
Program 1-
Python pattern program example


Source Code- Pycharm IDE

def python_pattern(n):  
    for i in range(0, n):      
        for j in range(0, i + 1):        
            print("* ", end="")      
        print("\r")
    n = 6
    python_pattern(n)



F:\web\venv\Scripts\python.exe F:/web/pattern.py
* * 
* * * 
* * * * 
* * * * * 
* * * * * * 

Process finished with exit code 0
--------------------------------------------------------------------------------------------------------------------------

Program 2


Python pattern program with space and Star(*) 

Pyhtan * Pattern Program with Space

Program Code-




def python_pattern(n):
    # outer loop to handle number of rows    
    # n in this case    for i in range(0, n):
        # inner loop to handle number 
        #of columns for space printing        
        for k in range(0, n-i):
            # printing space         
            print("  ", end="")
        # inner loop to handle number
        # of columns for star printing     
        for j in range(0, i + 1):
            # printing stars      
            print("* ", end="")
            # ending line after each row  
      print("\r")
    # Driver Code 
n = 6
python_pattern(n)

















Output-


               *
            * *
         * * *
      * * * *

   * * * * *
* * * * * *

---------------------------------------------------------------------------------

See- also- Python pattern program



Program 3- Palindrome No Program in Python

In this i will explain the palindome number program in python and also to expalin the same i also created a youtube video so you can check also complete step by step and also output in IDE. 

Palindrome number program in Pythan

Palindrome number program in Pythan


Palindrome No Program in Python-



num = int(input("enter a number: "))
temp = num
rev = 0while temp:
    rev = (rev * 10) + (temp % 10)
    temp = temp // 10if num == rev:
    print("No is palindrome")
else:
    print("No is not palindrome")



Output-
When entered Item is- 747
   No is Palindrome.

when entered Item is- 67
   No is notb Palindrome.


See Also-python palindorme no program


Program 4:- Pattern Program Number Sequence



This post will explain the logic and code for pattern program in Python. In this post you will understand how to right the code of a pattern which have the sequence in incresinng and descreasing sequence.




Python pattern from from incresing and descresing sequnce of numbers


 Pattern Code-
def python_pattern(n):
    for i in range(0, n):
        if n/2 >= i:
            for j in range(1, i+1):
                print(j, end=" ")
            print("\r")
        else:
            for j in range(1, n - i + 1):
                print(j, end=" ")
            print("\r")
n=10python_pattern(n)

Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Youtube Video of Complete Program


See Also-
Python pattern from from incresing and descresing sequnce of numbers


Program 4:-

Charchter Pattern Program Python

This example exaplain the new type of pattern program which is genearlly asked in Online exams and interview written exams and also university exam and college  exam. 
 

This example have the code of tringle charchter pattern program

tringle charchter pattern program in Python



Program Code:-


def alphapat_pattern (n):
    num = 65

    for i in range(0, n):

        for j in range(0, i + 1):
 
            ch = chr(num)

            print(ch, end=" ")

        num = num + 1
        print("\r")

 # When n =9, 7, 5, 4
n = 9alphapat_pattern(n)


Output:-
A
B B
C C C
D D D D
E E E E E 
F F F F F F
G G G G G G G
H H H H H H H H
I I I I I I I I I

Output:-
A
B B
C C C
D D D D
E E E E E 
F F F F F F
G G G G G G G

Output:-
A
B B
C C C
D D D D
E E E E E 

Output:-
A
B B
C C C
D D D D




See Also-







Program 6:-

Charchter Pattern Program Python Reverse Tringle

This example exaplain the new type of pattern program which is genearlly asked in Online exams and interview written exams and also university exam and college  exam. 
 

This example have the code of tringle charchter pattern program




Program Code:-

def alphapat_pattern (n):
    num = 65
    for i in range(0, n):
        for j in range(0, n-i):
            print(" ", end=" ")

        for j in range(0, i + 1):
            ch = chr(num)
            print(ch, end=" ")
        num = num + 1
        print("\r")

n = 9
alphapat_pattern(n)



when input variable is 9
Output:-
                A
              B B
            C C C
          D D D D
        E E E E E
      F F F F F F
    G G G G G G G
  H H H H H H H H
I I I I I I I I I

when input variable is 7
Output:-
                A
              B B
            C C C
          D D D D
        E E E E E
      F F F F F F
    G G G G G G G

when input variable is 5
Output:-
                A
              B B
            C C C
          D D D D
        E E E E E



when input variable is 4
Output:-
        A
    B B
  C C C
D D D D





See Also-







Program 7:-

Charchter Pattern Program Python Equilateral Tringle

This example exaplain the new type of pattern program which is genearlly asked in Online exams, interview and written exams and also university exam and college exam. 

This example have the code of tringle charchter pattern program

PYTHON PATTERN EQUILATERAL TRIANGLE



Program Code:-


def alphapat_pattern (n):
    num = 65
    for i in range(0, n):

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

        for j in range(0, i + 1):
            ch = chr(num)
            print(ch, end=" ")
        for j in range(0, i):
            ch = chr(num)
            print(ch, end=" ")
        num = num + 1
        print("\r")

n = 5alphapat_pattern(n)
# for varying the row and column length change the value of n

when input variable is 9

Output:-
                A
              B B B
            C C C C C 
          D D D D D D D
        E E E E E E E E E
      F F F F F F F F F F F
    G G G G G G G G G G G G G
  H H H H H H H H H H H H H H H
I I I I I I I I I I I I I I I I I


when input variable is 7

Output:-
                A
              B B B
            C C C C C
          D D D D D D D
        E E E E E E E E E 
      F F F F F F F F F F F 
    G G G G G G G G G G G G G

when input variable is 5

Output:-
                A
              B B B
            C C C C C
          D D D D D D D
        E E E E E E E E E



when input variable is 4

Output:-
        A
    B B B
  C C C C C
D D D D D D D 


Program 8:-

Sequence pattern Program

This example exaplain the new type of Sequence pattern program  with arrow type which is genearlly asked in Online exams related to programming in python, interview and written exams and also university exam and college exam. 

This example have the code of tringle charchter pattern program

Sequence pattern Program



Program Code:-

def python_pattern(n): for i in range(0, n): if n/2 >= i: for j in range(1, i+1): if j == i: print(j, end=" ") else: print(" ", end=" ") print("\r") else: for j in range(1, n - i + 1): if j == n-i: print(j, end=" ") else: print(" ", end=" ") print("\r") n=10python_pattern(n)


when input variable is 5

Output:-

1

  2
    3
      4
        5
      4
    3
  2
1


Program 9:-

Sequence pattern Program with Star and Number

These small program will help the learner to learn the basic of python programming and exaplain the new type of pattern program which is genearlly asked in Online exams related to programming in python, interview and written exams and also university exam and college exam. 

This example have the code of tringle charchter pattern program


Sequence pattern Program with Star and Number

# define the function# pass the varibledef python_pattern(n):
# define the loop for no of rows    for i in range(0, n):
        if n/2 >= i:
            for j in range(1, i+1):
               if j == i:
                   print(j, end=" ")
               else:
                   print("*", end=" ")

            print("\r")
        else:
            for j in range(1, n - i + 1):
                if j == n-i:
                    print(j, end=" ")
                else:
                    print("*", end=" ")
            print("\r")
# define the variblen=10python_pattern(n)
#run the program by pressing ctrl+shift+F10


Output

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

1 comment:

  1. Nice post.You have share some useful codes.Python is very popular language and easy to code.

    ReplyDelete

Translate