Python programs for printing pyramid patterns

Today, We want to share with you pattern program in python.In this post we will show you reverse pyramid pattern in python, hear for pattern program in python using single for loop we will give you demo and example for implement.In this post, we will learn about python convert float to string with an example.

Programs for printing pyramid patterns in Python

Example 1:

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

total = 10
getPattern(total)

Results

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

Example 2:


def getPattern(n):
    
    k = 2*n - 2
    for i in range(0, n):
     
        for j in range(0, k):
            print(end=" ")
     
        k = k - 2
     
        for j in range(0, i+1):
            print("* ", end="")
    
        print("\r")

total = 10
getPattern(total)

Results

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

Example 3:

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

total = 10
getPattern(total)

Results

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

Example 4: Number Pattern

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

total = 10
getPattern(total)

Results

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 

Example 5: Numbers without reassigning

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

total = 10
getPattern(total)

Results

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

I hope you get an idea about inverted star pattern in python.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment