Python Program to Print Star Pattern

Python program to print star pattern; Through this tutorial, i am going to show you how to write python program to print start pyramid, invert, asterisk, half invert, invert pyramid pattern.

Python Program to Print Star Pattern

See the following program to print star pattern programs in python:

  • Python Program To Print Star Pyramid Pattern
  • Inverted star pattern in python
  • Python Program to print inverted half pyramid
  • Python program to print Asterisk pattern
  • Python program to print pyramid
  • Python program to print inverted pyramid pattern

1: Python Program To Print Star Pyramid Pattern

# Python Program to print star pattern 
  
# Function to demonstrate printing pattern 
def pyramid (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 
        # values changing acc. to outer loop 
        for j in range(0, i+1): 
          
            # printing stars 
            print("* ",end="") 
       
        # ending line after each row 
        print("\r") 
  
# Driver Code 
n = 5
pyramid(n) 

Output

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

2: Inverted star pattern in python

# python Program print inverted star 
n=11
  
for i in range (n, 0, -1): 
    print((n-i) * ' ' + i * '*') 

Output

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

3: Python Program to print inverted half pyramid

rows = 6
for i in range (rows,0,-1):
    for j in range(0, i + 1):
        print("*", end=' ')
    print("\r")

Output

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

4: Python program to print Asterisk pattern

rows = 5
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")

Output

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

5: Python program to print pyramid

def full_pyramid(rows):
  
    for i in range(rows):
        print(' '*(rows-i-1) + '*'*(2*i+1))
full_pyramid(5)

Output

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

6: Python program to print inverted pyramid pattern

def inverted_pyramid(rows):
   
    for i in reversed(range(rows)):
        print(' '*(rows-i-1) + '*'*(2*i+1))
        
inverted_pyramid(5)

Output

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

Recommended Python Program

Recommended:-Python Map() Method

Be First to Comment

Leave a Reply

Your email address will not be published.