일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- Real or Not? NLP with Disaster Tweets
- 캐치카페
- 데이콘
- Baekjoon
- programmers
- 편스토랑 우승상품
- AI 경진대회
- 금융문자분석경진대회
- Git
- 편스토랑
- github
- leetcode
- 우분투
- Kaggle
- 프로그래머스 파이썬
- SW Expert Academy
- 백준
- 더현대서울 맛집
- Docker
- 파이썬
- ChatGPT
- gs25
- ubuntu
- 맥북
- 프로그래머스
- dacon
- 코로나19
- PYTHON
- hackerrank
- 자연어처리
- Today
- Total
솜씨좋은장씨
[HackerRank] Staircase (Python) 본문
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)
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[HackerRank] Stack and Queues : A Tale of Two Stacks (0) | 2020.04.04 |
---|---|
[HackerRank] Min-Max Sum (Python) (0) | 2020.04.03 |
[BaekJoon] 2133번 : 타일 채우기 (Python) (0) | 2020.04.01 |
[BaeKJoon] 10610번: 30 (Python) (0) | 2020.03.31 |
[BaeKJoon] 11047번: 동전 0 (Python) (0) | 2020.03.30 |