HackerRankMar 16, 2025

Staircase

Hazrat Ali

HackerRank

This is a staircase of size :

   #
  ##
 ###
####

Its base and height are both equal to . It is drawn using # symbols and spaces. The last line is not preceded by any spaces.

Write a program that prints a staircase of size .

Function Description

Complete the  function with the following parameter(s):

  • : an integer

Print

Print a staircase as described above. No value should be returned.
Note: The last line is not preceded by spaces. All lines are right-aligned.

Input Format

A single integer, , denoting the size of the staircase.

Constraints

 .

Sample Input

6 

Sample Output

     #
    ##
   ###
  ####
 #####
######

Explanation

The staircase is right-aligned, composed of # symbols and spaces, and has a height and width of n=6 .

 

Solution : 

#!/bin/python3
 
 import math
 import os
 import random
 import re
 import sys
 
 def staircase(n):
     for i in range(n):
         print((" " * (n - i - 1)) + "#" * (i + 1))
 
 if __name__ == '__main__':
     n = int(input().strip())
 
     staircase(n)

 

 

 

 

 

 

Comments