관리 메뉴

솜씨좋은장씨

[HackerRank] Staircase (Python) 본문

Programming/코딩 1일 1문제

[HackerRank] Staircase (Python)

솜씨좋은장씨 2020. 4. 2. 22:43
728x90
반응형

Consider a staircase of size : n = 4

   #
  ##
 ###
####

Observe that its base and height are both equal to n, and the image is drawn using # symbols and spaces. The last line is not preceded by any spaces.

Write a program that prints a staircase of size n.

 

Function Description

Complete the staircase function in the editor below. It should print a staircase as described above.

staircase has the following parameter(s):

  • n: an integer

Input Format

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

 

Constraints

0 < n <= 100

 

Output Format

Print a staircase of size  using # symbols and spaces.

 

Note: The last line must have 0 spaces in it.

 

Sample Input

0

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

# Complete the staircase function below.
def staircase(n):
    space = ' '
    shap = '#'
    index = n
    for i in range(1, n+1):
        print(space * (index - i) + shap * i)


if __name__ == '__main__':
    n = int(input())

    staircase(n)

 

 

SOMJANG/CODINGTEST_PRACTICE

1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.

github.com

Comments