Python 3 | Program to print double sided stair-case pattern

Below mentioned is the python 3 program to print the double sided stair case pattern.

Examples:

Input : 10
Output :

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

Note : This code only works for even values of n.



filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 Program to demonstrate 
# staircase pattern
  
# function definition
def pattern(n):
  
    # for loop for rows
    for i in range(1,n+1):
  
        # conditional operator
        k =i + 1 if(i % 2 != 0) else i
  
        # for loop for printing spaces
        for g in range(k,n):
            if g>=k:
                print(end="  ")
  
        # according to value of k carry
        # out further operation
        for j in range(0,k):
            if j == k - 1:
                print(" * ")
            else:
                print(" * ", end = " ")
  
  
# Driver code
n = 10
pattern(n)

chevron_right


Output:


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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.