🐍Python/Python_알고리즘

[알고리즘] 06. Staircase

728x90
반응형

Consider a staircase of size :

   #
  ##
 ###
####

Observe that its base and height are both equal to , 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 .

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, , denoting the size of the staircase.

Constraints

 .

Output Format

Print a staircase of size  using # symbols and spaces.

Note: The last line must have  spaces in it.

Sample Input

6 

Sample Output

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

Explanation

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





답 : 



#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the staircase function below.
def staircase(n):
for i in range(1,n+1):
stair = []
for _ in range(n,i,-1):
stair.append(" ")
for _ in range(i):
stair.append("#")
print(''.join(stair))


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

staircase(n)


총 6칸에 


5 1 

4 2 

3 3

2 4 

1 5

0 6 


이렇게 진행되도록 했다.

728x90
반응형