Signup/Sign In

Python Program to print double sided stair-case pattern

In this tutorial, we are going to print a double-sided staircase pattern. The staircase is right-left aligned, composed of * symbols and spaces, and has a height and width up to n. Here, n is an integer that is provided by the user.

Let us understand the input-output given below for a better understanding.

I/O Staircase

Here, the user will be prompted to give the input which will be the size, and the output is desired double-sided staircase pattern.

Algorithm

We have seen the Input and Output of the double-sided staircase pattern now let's dive deep into the algorithm part followed by the code:

  1. Create a function staircase_pattern()
  2. Pass n as a parameter in the function
  3. Create a for loop for the rows
  4. Mark a conditional operator
  5. Create for loop for printing spaces
  6. According to value carry on with the looping operation
  7. The result will be the desired pattern
  8. Print the pattern

Program

As of now, we have a rough understanding of printing the double-sided staircase pattern. Let us now look at the code influenced by the algorithm:

def pattern(n):
    for a in range(1,n+1):
        c =a + 1 if(a % 2 != 0) else a
        for b in range(c,n):
            if b>=c:
                print(end="  ")
        for d in range(0,c):
            if d == c - 1:
                print(" * ")
            else:
                print(" * ", end = " ")
# Driver code
n = int(input("Please enter the size:"))
if n<10:
    print("Enter range above 10")
else:
    pattern(n)


Please enter the size:10
* *
* *
* * * *
* * * *
* * * * * *
* * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * * * *
* * * * * * * * * *

Conclusion

In this tutorial, we have printed a double-sided staircase pattern in the python programming language. The staircase is composed of * and spaces. You can change the symbols according to your choice.



About the author:
Nikita Pandey is a talented author and expert in programming languages such as C, C++, and Java. Her writing is informative, engaging, and offers practical insights and tips for programmers at all levels.